diff --git a/docs/en_US/release_notes_4_26.rst b/docs/en_US/release_notes_4_26.rst index d4cdb6fb7..a14c59f61 100644 --- a/docs/en_US/release_notes_4_26.rst +++ b/docs/en_US/release_notes_4_26.rst @@ -32,6 +32,7 @@ Bug fixes | `Issue #5748 `_ - Fixed incorrect reverse engineering SQL for Foreign key when creating a table. | `Issue #5751 `_ - Enable the 'Configure' and 'View log' menu option when the server taking longer than usual time to start. | `Issue #5754 `_ - Fixed an issue where schema diff is not working when providing the options to Foreign Data Wrapper, Foreign Server, and User Mapping. +| `Issue #5765 `_ - Fixed an issue in the query tool when columns are having the same name as javascript object internal functions. | `Issue #5766 `_ - Fixed string indices must be integers issue for PostgreSQL < 9.3. | `Issue #5773 `_ - Fixed an issue where the application ignores the fixed port configuration value. | `Issue #5775 `_ - Ensure that 'setup-web.sh' should work in Debian 10. \ No newline at end of file diff --git a/web/pgadmin/static/js/is_native.js b/web/pgadmin/static/js/is_native.js new file mode 100644 index 000000000..3adc516ca --- /dev/null +++ b/web/pgadmin/static/js/is_native.js @@ -0,0 +1,42 @@ +/* Code to check if the object or function is native JS + * Author: John-David Dalton + */ +(function() { + + // Used to resolve the internal `[[Class]]` of values + var toString = Object.prototype.toString; + + // Used to resolve the decompiled source of functions + var fnToString = Function.prototype.toString; + + // Used to detect host constructors (Safari > 4; really typed array specific) + var reHostCtor = /^\[object .+?Constructor\]$/; + + // Compile a regexp using a common native method as a template. + // We chose `Object#toString` because there's a good chance it is not being mucked with. + var reNative = RegExp('^' + + // Coerce `Object#toString` to a string + String(toString) + // Escape any special regexp characters + .replace(/[.*+?^${}()|[\]\/\\]/g, '\\$&') + // Replace mentions of `toString` with `.*?` to keep the template generic. + // Replace thing like `for ...` to support environments like Rhino which add extra info + // such as method arity. + .replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' + ); + + function isNative(value) { + var type = typeof value; + return type == 'function' + // Use `Function#toString` to bypass the value's own `toString` method + // and avoid being faked out. + ? reNative.test(fnToString.call(value)) + // Fallback to a host object check because some environments will represent + // things like typed arrays as DOM methods which may not conform to the + // normal native pattern. + : (value && type == 'object' && reHostCtor.test(toString.call(value))) || false; + } + + // export however you want + module.exports = isNative; +}()); diff --git a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js index 5c6b4ae8c..060207202 100644 --- a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js +++ b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js @@ -40,6 +40,7 @@ define('tools.querytool', [ 'sources/csrf', 'tools/datagrid/static/js/datagrid_panel_title', 'sources/window', + 'sources/is_native', 'sources/../bundle/slickgrid', 'pgadmin.file_manager', 'slick.pgadmin.formatters', @@ -54,7 +55,7 @@ define('tools.querytool', [ GeometryViewer, historyColl, queryHist, querySources, keyboardShortcuts, queryToolActions, queryToolNotifications, Datagrid, modifyAnimation, calculateQueryRunTime, callRenderAfterPoll, queryToolPref, queryTxnStatus, csrfToken, panelTitleFunc, - pgWindow) { + pgWindow, isNative) { /* Return back, this has been called more than once */ if (pgAdmin.SqlEditor) return pgAdmin.SqlEditor; @@ -789,10 +790,14 @@ define('tools.querytool', [ c.display_name = _.escape(c.display_name); c.column_type = _.escape(c.column_type); + // If the keys have name from existing JS keywords then it may + // create problem. eg - contructor, hasOwnProperty. + // nonative_field is field with extra double quotes var options = { id: _.escape(c.name), pos: c.pos, field: c.name, + nonative_field: `"${c.name}"`, name: c.label, display_name: c.display_name, column_type: c.column_type, @@ -809,11 +814,11 @@ define('tools.querytool', [ var column_type = c.column_type.trim(); var label = c.name.length > column_type.length ? _.escape(c.display_name) : column_type; - if (_.isUndefined(column_size[table_name][c.name])) { + if (_.isUndefined(column_size[table_name][options.nonative_field])) { options['width'] = SqlEditorUtils.calculateColumnWidth(label); - column_size[table_name][c.name] = options['width']; + column_size[table_name][c.nonative_field] = options['width']; } else { - options['width'] = column_size[table_name][c.name]; + options['width'] = column_size[table_name][options.nonative_field]; } // If grid is editable then add editor else make it readonly if (c.cell == 'oid' && c.name == 'oid') { @@ -999,7 +1004,7 @@ define('tools.querytool', [ var cols = this.getColumns(); _.each(cols, function(col) { var col_size = self.handler['col_size']; - col_size[self.handler['table_name']][col['id']] = col['width']; + col_size[self.handler['table_name']][col['nonative_field']] = col['width']; }); }.bind(grid)); @@ -1191,6 +1196,13 @@ define('tools.querytool', [ item_current[self.client_primary_key] = _key; } + // When adding new rows, mark all native JS keywords undefined if not already set + _.each(args.grid.getColumns(), function(col){ + if(isNative(item_current[col.field])) { + item_current[col.field] = undefined; + } + }); + data_view.addItem(item_current); self.handler.data_store.added[_key] = { 'err': false,