From d88c4fed1e03dff55f3668f3cc399966c5834e76 Mon Sep 17 00:00:00 2001 From: Corbin Robb Date: Thu, 3 Feb 2022 11:33:16 -0700 Subject: [PATCH] add test for encode/decode --- .../src/views/CRUD/utils.test.tsx | 19 +++++++++++++++++++ superset-frontend/src/views/CRUD/utils.tsx | 6 ++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/superset-frontend/src/views/CRUD/utils.test.tsx b/superset-frontend/src/views/CRUD/utils.test.tsx index 2b95319d85d5b..e303c771883d8 100644 --- a/superset-frontend/src/views/CRUD/utils.test.tsx +++ b/superset-frontend/src/views/CRUD/utils.test.tsx @@ -16,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +import rison from 'rison'; import { isNeedsPassword, isAlreadyExists, @@ -171,3 +172,21 @@ test('does not ask for password when the import type is wrong', () => { }; expect(hasTerminalValidation(error.errors)).toBe(true); }); + +test('successfully modified rison to encode correctly', () => { + const problemCharacters = '& # ? ^ { } [ ] | " = + `'; + + const testObject = problemCharacters.split(' ').reduce((a, c) => { + // eslint-disable-next-line no-param-reassign + a[c] = c; + return a; + }, {}); + + const actualEncoding = rison.encode(testObject); + + const expectedEncoding = + "('\"':'\"','#':'#','&':'&','+':'+','=':'=','?':'?','[':'[',']':']','^':'^','`':'`','{':'{','|':'|','}':'}')"; + + expect(actualEncoding).toEqual(expectedEncoding); + expect(rison.decode(actualEncoding)).toEqual(testObject); +}); diff --git a/superset-frontend/src/views/CRUD/utils.tsx b/superset-frontend/src/views/CRUD/utils.tsx index cb5c01db55d0b..679409dd7b94b 100644 --- a/superset-frontend/src/views/CRUD/utils.tsx +++ b/superset-frontend/src/views/CRUD/utils.tsx @@ -35,7 +35,7 @@ import { Dashboard, Filters } from './types'; // Modifies the rison encoding slightly to match the backend's // rison encoding/decoding. Applies globally. Code pulled from rison.js -const fixRisonEncodeDecode = () => { +(() => { const risonRef: { not_idchar: string; not_idstart: string; @@ -60,9 +60,7 @@ const fixRisonEncodeDecode = () => { risonRef.id_ok = new RegExp(`^${idrx}$`); risonRef.next_id = new RegExp(idrx, 'g'); -}; - -fixRisonEncodeDecode(); +})(); const createFetchResourceMethod = (method: string) =>