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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
904e530f74
commit
73e7298525
@@ -28,6 +28,14 @@ test('parse required numeric parameters from uri', () => {
|
|||||||
expect(getRequiredParameters(testURI)).toEqual(expectedResult);
|
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', () => {
|
test('replace required parameters with values', () => {
|
||||||
const testURI =
|
const testURI =
|
||||||
'fb://test_uri/?parameter1={parameter1}¶meter2={parameter2}';
|
'fb://test_uri/?parameter1={parameter1}¶meter2={parameter2}';
|
||||||
|
|||||||
@@ -60,12 +60,20 @@ export const replaceRequiredParametersWithValues = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getRequiredParameters = (uri: string) => {
|
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<string> = [];
|
const matches: Array<string> = [];
|
||||||
let match = parameterRegExp.exec(uri);
|
let match = parameterRegExp.exec(uri);
|
||||||
while (match != null) {
|
while (match != null) {
|
||||||
if (match[0]) {
|
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);
|
match = parameterRegExp.exec(uri);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user