public inbox for [email protected]
help / color / mirror / Atom feed[pgAdmin][RM5765] Invalid markup for viewing table with field named "constructor"
2+ messages / 2 participants
[nested] [flat]
* [pgAdmin][RM5765] Invalid markup for viewing table with field named "constructor"
@ 2020-09-07 05:43 Aditya Toshniwal <[email protected]>
2020-09-07 13:18 ` Re: [pgAdmin][RM5765] Invalid markup for viewing table with field named "constructor" Akshay Joshi <[email protected]>
0 siblings, 1 reply; 2+ messages in thread
From: Aditya Toshniwal @ 2020-09-07 05:43 UTC (permalink / raw)
To: pgadmin-hackers
Hi Hackers,
Attached is the patch to handle issues in the query tool when columns are
having names same as JS object internal functions like constructor,
hasOwnProperty, etc.
Please review.
--
Thanks,
Aditya Toshniwal
pgAdmin hacker | Sr. Software Engineer | *edbpostgres.com*
<http://edbpostgres.com;
"Don't Complain about Heat, Plant a TREE"
Attachments:
[application/octet-stream] RM5765.patch (5.1K, 3-RM5765.patch)
download | inline diff:
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 a0724ff9e..c19cfcda0 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,
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: [pgAdmin][RM5765] Invalid markup for viewing table with field named "constructor"
2020-09-07 05:43 [pgAdmin][RM5765] Invalid markup for viewing table with field named "constructor" Aditya Toshniwal <[email protected]>
@ 2020-09-07 13:18 ` Akshay Joshi <[email protected]>
0 siblings, 0 replies; 2+ messages in thread
From: Akshay Joshi @ 2020-09-07 13:18 UTC (permalink / raw)
To: Aditya Toshniwal <[email protected]>; +Cc: pgadmin-hackers
Thanks, patch applied.
On Mon, Sep 7, 2020 at 11:14 AM Aditya Toshniwal <
[email protected]> wrote:
> Hi Hackers,
>
> Attached is the patch to handle issues in the query tool when columns are
> having names same as JS object internal functions like constructor,
> hasOwnProperty, etc.
>
> Please review.
>
> --
> Thanks,
> Aditya Toshniwal
> pgAdmin hacker | Sr. Software Engineer | *edbpostgres.com*
> <http://edbpostgres.com;
> "Don't Complain about Heat, Plant a TREE"
>
--
*Thanks & Regards*
*Akshay Joshi*
*pgAdmin Hacker | Sr. Software Architect*
*EDB Postgres <http://edbpostgres.com>*
*Mobile: +91 976-788-8246*
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2020-09-07 13:18 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-09-07 05:43 [pgAdmin][RM5765] Invalid markup for viewing table with field named "constructor" Aditya Toshniwal <[email protected]>
2020-09-07 13:18 ` Akshay Joshi <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox