From 024cfd2fab969df0ed4062177451b83eb814f4b8 Mon Sep 17 00:00:00 2001
From: Aditya Toshniwal <aditya.toshniwal@enterprisedb.com>
Date: Fri, 12 Apr 2019 15:07:07 +0530
Subject: [PATCH] 1) Ensure that JSON strings as comments should be added
 properly for all the objects. Fixes #3582 2) Fixed alignment issue of columns
 in definition section of Index node. Fixes #4121

---
 docs/en_US/release_notes_4_6.rst              |  2 ++
 .../servers/databases/__init__.py             |  7 ++++++-
 .../foreign_data_wrappers/__init__.py         |  7 ++++++-
 .../foreign_servers/__init__.py               |  7 ++++++-
 .../servers/databases/languages/__init__.py   |  7 ++++++-
 .../servers/databases/schemas/__init__.py     |  7 ++++++-
 .../databases/schemas/collations/__init__.py  |  7 ++++++-
 .../schemas/fts_configurations/__init__.py    |  7 ++++++-
 .../schemas/fts_dictionaries/__init__.py      |  7 ++++++-
 .../databases/schemas/fts_parsers/__init__.py |  7 ++++++-
 .../schemas/fts_templates/__init__.py         |  7 ++++++-
 .../databases/schemas/sequences/__init__.py   |  7 ++++++-
 .../databases/schemas/tables/__init__.py      | 21 ++++++++++++++++---
 .../constraints/check_constraint/__init__.py  | 14 +++++++++++--
 .../exclusion_constraint/__init__.py          | 14 +++++++++++--
 .../constraints/foreign_key/__init__.py       | 14 +++++++++++--
 .../constraints/index_constraint/__init__.py  | 14 +++++++++++--
 .../schemas/tables/indexes/__init__.py        | 14 +++++++++++--
 .../schemas/tables/indexes/static/js/index.js |  1 +
 .../schemas/tables/triggers/__init__.py       | 14 +++++++++++--
 .../databases/schemas/views/__init__.py       |  7 ++++++-
 .../servers/tablespaces/__init__.py           |  7 ++++++-
 22 files changed, 171 insertions(+), 28 deletions(-)

#diff --git a/docs/en_US/release_notes_4_6.rst b/docs/en_US/release_notes_4_6.rst
#index 8c671ca42..2cd056677 100644
#--- a/docs/en_US/release_notes_4_6.rst
#+++ b/docs/en_US/release_notes_4_6.rst
#@@ -15,7 +15,9 @@ Features
# Bug fixes
# *********
# 
#+| `Bug #3582 <https://redmine.postgresql.org/issues/3582>`_ - Ensure that JSON strings as comments should be added properly for all the objects.
# | `Bug #3938 <https://redmine.postgresql.org/issues/3938>`_ - Added support for Default Partition.
# | `Bug #4104 <https://redmine.postgresql.org/issues/4104>`_ - Ensure that record should be add/edited for root partition table with primary keys.
#+| `Bug #4121 <https://redmine.postgresql.org/issues/4121>`_ - Fixed alignment issue of columns in definition section of Index node.
# | `Bug #4138 <https://redmine.postgresql.org/issues/4138>`_ - Fix an issue where the dropdown becomes misaligned/displaced.
# | `Bug #4161 <https://redmine.postgresql.org/issues/4161>`_ - Ensure that parameters of procedures for EPAS server 10 and below should be set/reset properly.
#\ No newline at end of file
diff --git a/web/pgadmin/browser/server_groups/servers/databases/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/__init__.py
index 731620592..53a322d48 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/__init__.py
@@ -805,7 +805,12 @@ def msql(self, gid, sid, did=None):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('comments',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
         status, res = self.get_sql(gid, sid, data, did)
diff --git a/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/__init__.py
index c69ee4643..f9966975e 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/__init__.py
@@ -555,7 +555,12 @@ def msql(self, gid, sid, did, fid=None):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('description',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
         try:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/__init__.py
index 9d3f6990f..10f919c95 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/__init__.py
@@ -578,7 +578,12 @@ def msql(self, gid, sid, did, fid, fsid=None):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('description',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
         try:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/languages/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/languages/__init__.py
index 25c5f5440..11f835c7d 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/languages/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/languages/__init__.py
@@ -558,7 +558,12 @@ def msql(self, gid, sid, did, lid=None):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('description',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
         try:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/__init__.py
index 2ace75738..5404c5022 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/__init__.py
@@ -724,7 +724,12 @@ def msql(self, gid, sid, did, scid=None):
         data = dict()
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('description',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/collations/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/collations/__init__.py
index e61f90f64..51f530a71 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/collations/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/collations/__init__.py
@@ -602,7 +602,12 @@ def msql(self, gid, sid, did, scid, coid=None):
         data = dict()
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('description',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_configurations/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_configurations/__init__.py
index 685587661..df9bb4e46 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_configurations/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_configurations/__init__.py
@@ -612,7 +612,12 @@ def msql(self, gid, sid, did, scid, cfgid=None):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('description',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/__init__.py
index 0d8bc2156..e95d8abd9 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/__init__.py
@@ -607,7 +607,12 @@ def msql(self, gid, sid, did, scid, dcid=None):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('description',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parsers/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parsers/__init__.py
index 281a77d38..62d93768c 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parsers/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parsers/__init__.py
@@ -534,7 +534,12 @@ def msql(self, gid, sid, did, scid, pid=None):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('description',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/__init__.py
index feb590d2c..604256240 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/__init__.py
@@ -507,7 +507,12 @@ def msql(self, gid, sid, did, scid, tid=None):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('description',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/__init__.py
index 5baeac08e..a778240fa 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/__init__.py
@@ -538,7 +538,12 @@ def msql(self, gid, sid, did, scid, seid=None):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('comment',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
index 6fa25b29a..0f017e885 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
@@ -909,7 +909,12 @@ def create(self, gid, sid, did, scid):
 
         for k, v in data.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('description',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except (ValueError, TypeError, KeyError):
                 data[k] = v
 
@@ -1036,7 +1041,12 @@ def update(self, gid, sid, did, scid, tid):
 
         for k, v in data.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('description',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except (ValueError, TypeError, KeyError):
                 data[k] = v
 
@@ -1223,7 +1233,12 @@ def msql(self, gid, sid, did, scid, tid=None):
         res = None
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('description',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except (ValueError, TypeError, KeyError):
                 data[k] = v
 
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/__init__.py
index 474487ca1..aa422066a 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/__init__.py
@@ -495,7 +495,12 @@ def create(self, gid, sid, did, scid, tid, cid=None):
 
         for k, v in data.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('comment',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except (ValueError, TypeError, KeyError):
                 data[k] = v
 
@@ -762,7 +767,12 @@ def msql(self, gid, sid, did, scid, tid, cid=None):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('comment',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/__init__.py
index 4024e0b52..e204f5e09 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/__init__.py
@@ -558,7 +558,12 @@ def create(self, gid, sid, did, scid, tid, exid=None):
 
         for k, v in data.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('comment',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except (ValueError, TypeError, KeyError):
                 data[k] = v
 
@@ -788,7 +793,12 @@ def msql(self, gid, sid, did, scid, tid, exid=None):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('comment',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/__init__.py
index 68a211524..e2f04afba 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/__init__.py
@@ -563,7 +563,12 @@ def create(self, gid, sid, did, scid, tid, fkid=None):
 
         for k, v in data.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('comment',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except (ValueError, TypeError, KeyError):
                 data[k] = v
 
@@ -827,7 +832,12 @@ def msql(self, gid, sid, did, scid, tid, fkid=None):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('comment',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/__init__.py
index 6a9162a85..dac45a0d0 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/__init__.py
@@ -576,7 +576,12 @@ def create(self, gid, sid, did, scid, tid, cid=None):
 
         for k, v in data.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('comment',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except (ValueError, TypeError, KeyError):
                 data[k] = v
 
@@ -828,7 +833,12 @@ def msql(self, gid, sid, did, scid, tid, cid=None):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('comment',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py
index c9127412c..269df983d 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py
@@ -621,7 +621,12 @@ def create(self, gid, sid, did, scid, tid):
 
         for k, v in data.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('description',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except (ValueError, TypeError, KeyError):
                 data[k] = v
 
@@ -826,7 +831,12 @@ def msql(self, gid, sid, did, scid, tid, idx=None):
         data = dict()
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('description',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/static/js/index.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/static/js/index.js
index f075d5d9b..0220a9410 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/static/js/index.js
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/static/js/index.js
@@ -230,6 +230,7 @@ define('pgadmin.node.index', [
       hasSQL:  true,
       hasDepends: true,
       hasStatistics: true,
+      width: pgBrowser.stdW.md + 'px',
       statsPrettifyFields: [gettext('Size'), gettext('Index size')],
       Init: function() {
         /* Avoid mulitple registration of menus */
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/__init__.py
index 7d2b0f114..0dc8de6ea 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/__init__.py
@@ -619,7 +619,12 @@ def create(self, gid, sid, did, scid, tid):
 
         for k, v in data.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('description',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except (ValueError, TypeError, KeyError):
                 data[k] = v
 
@@ -827,7 +832,12 @@ def msql(self, gid, sid, did, scid, tid, trid=None):
         data = dict()
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('description',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/__init__.py
index d5ac0df07..44c3bc9e1 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/__init__.py
@@ -647,7 +647,12 @@ def msql(self, gid, sid, did, scid, vid=None):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('comment',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
diff --git a/web/pgadmin/browser/server_groups/servers/tablespaces/__init__.py b/web/pgadmin/browser/server_groups/servers/tablespaces/__init__.py
index 8b7e1da9d..46940b4e7 100644
--- a/web/pgadmin/browser/server_groups/servers/tablespaces/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/tablespaces/__init__.py
@@ -457,7 +457,12 @@ def msql(self, gid, sid, tsid=None):
         data = dict()
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v, encoding='utf-8')
+                # comments should be taken as is because if user enters a
+                # json comment it is parsed by loads which should not happen
+                if k in ('description',):
+                    data[k] = v
+                else:
+                    data[k] = json.loads(v, encoding='utf-8')
             except ValueError as ve:
                 current_app.logger.exception(ve)
                 data[k] = v
