diff --git a/packages/react-navigation/src/routers/StackRouter.js b/packages/react-navigation/src/routers/StackRouter.js index eb59153f..56d6af19 100644 --- a/packages/react-navigation/src/routers/StackRouter.js +++ b/packages/react-navigation/src/routers/StackRouter.js @@ -529,7 +529,15 @@ export default (routeConfigs, stackConfig = {}) => { } const nextResult = result || {}; const paramName = key.name; - nextResult[paramName] = matchResult; + + let decodedMatchResult; + try { + decodedMatchResult = decodeURIComponent(matchResult); + } catch (e) { + // ignore `URIError: malformed URI` + } + + nextResult[paramName] = decodedMatchResult || matchResult; return nextResult; }, queryParams); diff --git a/packages/react-navigation/src/routers/__tests__/StackRouter-test.js b/packages/react-navigation/src/routers/__tests__/StackRouter-test.js index 5d2e4376..c03d59ca 100644 --- a/packages/react-navigation/src/routers/__tests__/StackRouter-test.js +++ b/packages/react-navigation/src/routers/__tests__/StackRouter-test.js @@ -1506,6 +1506,28 @@ describe('StackRouter', () => { ); }); + test('URI encoded string get passed to deep link', () => { + const uri = 'people/2018%2F02%2F07'; + const action = TestStackRouter.getActionForPathAndParams(uri); + expect(action).toEqual({ + routeName: 'person', + params: { + id: '2018/02/07', + }, + type: NavigationActions.NAVIGATE, + }); + + const malformedUri = 'people/%E0%A4%A'; + const action2 = TestStackRouter.getActionForPathAndParams(malformedUri); + expect(action2).toEqual({ + routeName: 'person', + params: { + id: '%E0%A4%A', + }, + type: NavigationActions.NAVIGATE, + }); + }); + test('Querystring params get passed to nested deep link', () => { // uri with two non-empty query param values const uri = 'main/p/4/list/10259959195?code=test&foo=bar';