From 73e729852536f207ced1934a05a2efba80c919ec Mon Sep 17 00:00:00 2001 From: Andrey Goncharov Date: Mon, 5 Dec 2022 04:14:34 -0800 Subject: [PATCH] Ignore parameters with pre-filled JSON values Summary: https://fb.workplace.com/groups/flippersupport/permalink/1513232162490770/ Apparently, some apps use JSONs as values for their params Reviewed By: lblasa Differential Revision: D41684474 fbshipit-source-id: 4ab19313ede06b226715a5c398728f0be7feddaf --- .../public/navigation/__tests__/testURI.node.tsx | 8 ++++++++ desktop/plugins/public/navigation/util/uri.tsx | 12 ++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/desktop/plugins/public/navigation/__tests__/testURI.node.tsx b/desktop/plugins/public/navigation/__tests__/testURI.node.tsx index 8bac54e30..78eb83048 100644 --- a/desktop/plugins/public/navigation/__tests__/testURI.node.tsx +++ b/desktop/plugins/public/navigation/__tests__/testURI.node.tsx @@ -28,6 +28,14 @@ test('parse required numeric parameters from uri', () => { expect(getRequiredParameters(testURI)).toEqual(expectedResult); }); +// https://fb.workplace.com/groups/flippersupport/permalink/1513232162490770/ +test('ignore params with JSON values', () => { + const testURI = + 'fb://test_uri/?parameter1={"test":"value"}¶meter2="{\\"test\\":\\"value\\"}"'; + const expectedResult: string[] = []; + expect(getRequiredParameters(testURI)).toEqual(expectedResult); +}); + test('replace required parameters with values', () => { const testURI = 'fb://test_uri/?parameter1={parameter1}¶meter2={parameter2}'; diff --git a/desktop/plugins/public/navigation/util/uri.tsx b/desktop/plugins/public/navigation/util/uri.tsx index 69b9996bd..fae2610f3 100644 --- a/desktop/plugins/public/navigation/util/uri.tsx +++ b/desktop/plugins/public/navigation/util/uri.tsx @@ -60,12 +60,20 @@ export const replaceRequiredParametersWithValues = ( }; export const getRequiredParameters = (uri: string) => { - const parameterRegExp = /{[^?]*?}/g; + // Add = to the matching group to filter out stringified JSON parameters + const parameterRegExp = /={[^?]*?}/g; const matches: Array = []; let match = parameterRegExp.exec(uri); while (match != null) { if (match[0]) { - matches.push(match[0]); + // Remove = from the match + const target = match[0].substring(1); + try { + // If the value could be parsed asa valid JSON, ignore it + JSON.parse(target); + } catch { + matches.push(target); + } } match = parameterRegExp.exec(uri); }