diff --git a/web/pgadmin/browser/static/js/browser.js b/web/pgadmin/browser/static/js/browser.js index e3d758fb..f4e5168a 100644 --- a/web/pgadmin/browser/static/js/browser.js +++ b/web/pgadmin/browser/static/js/browser.js @@ -1942,6 +1942,8 @@ define('pgadmin.browser', [ version: M[1], }; }, + + pgCustomSlashValue: () => '!PG!', }); /* Remove paste event mapping from CodeMirror's emacsy KeyMap binding diff --git a/web/pgadmin/static/js/sqleditor_utils.js b/web/pgadmin/static/js/sqleditor_utils.js index 19ad772e..75603efb 100644 --- a/web/pgadmin/static/js/sqleditor_utils.js +++ b/web/pgadmin/static/js/sqleditor_utils.js @@ -195,6 +195,13 @@ define(['jquery', 'sources/gettext', 'sources/url_for'], } return '1em'; }, + + encodeSlashInTheString: (pgBrowserObj, value) => { + while (value && value.indexOf('/') !== -1) { + value = value.replace('/', pgBrowserObj.pgCustomSlashValue()); + } + return encodeURIComponent(value); + }, }; return sqlEditorUtils; }); diff --git a/web/pgadmin/tools/datagrid/__init__.py b/web/pgadmin/tools/datagrid/__init__.py index 3736e38a..15235aaf 100644 --- a/web/pgadmin/tools/datagrid/__init__.py +++ b/web/pgadmin/tools/datagrid/__init__.py @@ -230,6 +230,10 @@ def panel(trans_id, is_query_tool, editor_title): else: server_type = None + # If title contains the custom encoded slash(es) in it then replace it + if editor_title.find('!PG!') != -1: + editor_title = editor_title.replace('!PG!', '/') + # We need client OS information to render correct Keyboard shortcuts user_agent = UserAgent(request.headers.get('User-Agent')) diff --git a/web/pgadmin/tools/datagrid/static/js/datagrid.js b/web/pgadmin/tools/datagrid/static/js/datagrid.js index 0a795fab..27a548d4 100644 --- a/web/pgadmin/tools/datagrid/static/js/datagrid.js +++ b/web/pgadmin/tools/datagrid/static/js/datagrid.js @@ -234,17 +234,7 @@ define('pgadmin.datagrid', [ return; } - var nsp_name = ''; - - if (parentData.schema != undefined) { - nsp_name = parentData.schema.label; - } - else if (parentData.view != undefined) { - nsp_name = parentData.view.label; - } - else if (parentData.catalog != undefined) { - nsp_name = parentData.catalog.label; - } + let nsp_name = showData.retrieveNameSpaceName(parentData); var url_params = { 'cmd_type': data.mnuid, @@ -263,8 +253,8 @@ define('pgadmin.datagrid', [ 'did': url_params['did'], 'obj_id': url_params['obj_id'], }); - var grid_title = parentData.server.label + '-' + parentData.database.label + '-' - + nsp_name + '.' + d.label; + + let grid_title = showData.generateDatagridTitle(parentData, nsp_name, d); // Create filter dialog using alertify if (!alertify.filterDialog) { @@ -484,7 +474,9 @@ define('pgadmin.datagrid', [ var url_params = { 'trans_id': trans_obj.gridTransId, 'is_query_tool': trans_obj.is_query_tool, - 'editor_title': encodeURIComponent(grid_title), + 'editor_title': sqlEditorUtils.encodeSlashInTheString( + pgBrowser, grid_title + ), }, baseUrl = url_for('datagrid.panel', url_params) + '?' + 'query_url=' + encodeURI(trans_obj.sURL) + '&server_type=' + encodeURIComponent(trans_obj.server_type); diff --git a/web/pgadmin/tools/datagrid/static/js/show_data.js b/web/pgadmin/tools/datagrid/static/js/show_data.js index 33f0db1f..eca27526 100644 --- a/web/pgadmin/tools/datagrid/static/js/show_data.js +++ b/web/pgadmin/tools/datagrid/static/js/show_data.js @@ -52,7 +52,7 @@ export function showDataGrid( } -function retrieveNameSpaceName(parentData) { +export function retrieveNameSpaceName(parentData) { if (parentData.schema !== undefined) { return parentData.schema.label; } @@ -87,6 +87,6 @@ function hasSchemaOrCatalogOrViewInformation(parentData) { parentData.catalog !== undefined; } -function generateDatagridTitle(parentData, namespaceName, nodeData) { +export function generateDatagridTitle(parentData, namespaceName, nodeData) { return `${namespaceName}.${nodeData.label}`; } diff --git a/web/regression/javascript/sqleditor_utils_spec.js b/web/regression/javascript/sqleditor_utils_spec.js index f2a70c0a..72b25576 100644 --- a/web/regression/javascript/sqleditor_utils_spec.js +++ b/web/regression/javascript/sqleditor_utils_spec.js @@ -10,6 +10,12 @@ define(['sources/sqleditor_utils'], function (SqlEditorUtils) { describe('SqlEditorUtils', function () { + let pgBrowserMock; + beforeEach(() => { + pgBrowserMock = { + 'pgCustomSlashValue': () => '!PG!', + }; + }); describe('Generate a random string of size 10', function () { it('returns string of length 10', function () { @@ -36,5 +42,37 @@ function (SqlEditorUtils) { expect(SqlEditorUtils.calcFontSize(2)).toEqual('2em'); }); }); + + describe('Encodes the slashes', function () { + it('it will encode the slashes', function () { + expect( + SqlEditorUtils.encodeSlashInTheString(pgBrowserMock, '/') + ).toEqual('!PG!'); + }); + + it('it will encode if slashes are present', function () { + expect( + SqlEditorUtils.encodeSlashInTheString(pgBrowserMock, 'my/test') + ).toEqual('my!PG!test'); + }); + + it('it will encode all the slashes are present', function () { + expect( + SqlEditorUtils.encodeSlashInTheString(pgBrowserMock, 'my/test/value') + ).toEqual('my!PG!test!PG!value'); + }); + + it('it will not cusotm encode if slash is not present', function () { + expect( + SqlEditorUtils.encodeSlashInTheString(pgBrowserMock, 'mytest') + ).toEqual('mytest'); + }); + + it('it will not custom encode if value is not present', function () { + expect( + SqlEditorUtils.encodeSlashInTheString(pgBrowserMock, null) + ).toEqual('null'); + }); + }); }); });