Skip to content

Commit

Permalink
[linking] decode query params (#6774)
Browse files Browse the repository at this point in the history
* [linking] decode query params

* move code to beforeEach and afterEach
  • Loading branch information
cruzach committed Jan 16, 2020
1 parent 49e074d commit e50f4c3
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/expo/build/Linking/Linking.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo/build/Linking/Linking.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions packages/expo/src/Linking/Linking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ function parse(url: string): ParsedURL {

const parsed = URL(url, /* parseQueryString */ true);

for (const param in parsed.query) {
parsed.query[param] = decodeURIComponent(parsed.query[param]!);
}
let queryParams = parsed.query;

let hostUri = HOST_URI || '';
Expand Down
25 changes: 25 additions & 0 deletions packages/expo/src/__tests__/Linking-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Linking from '../Linking/Linking';
import { QueryParams } from '../Linking/Linking.types';

describe('parse', () => {
test.each<string>([
Expand All @@ -11,6 +12,9 @@ describe('parse', () => {
'https://example.com/test/path',
'https://example.com:8000/test/path',
'https://example.com:8000/test/path+with+plus',
'https://example.com/test/path?query=do+not+escape',
'https://example.com/test/path?missingQueryValue=',
'custom:///?shouldBeEscaped=x%252By%2540xxx.com',
'custom:///test/path?foo=bar',
'custom:///',
'custom://',
Expand All @@ -20,3 +24,24 @@ describe('parse', () => {
expect(Linking.parse(url)).toMatchSnapshot();
});
});

describe('makeUrl queries', () => {
const consoleWarn = console.warn;
beforeEach(() => {
console.warn = jest.fn();
});

afterEach(() => {
console.warn = consoleWarn;
});

test.each<QueryParams>([
{ shouldEscape: '%2b%20' },
{ escapePluses: 'email+with+plus@whatever.com' },
{ emptyParam: '' },
{ undefinedParam: undefined },
{ lotsOfSlashes: '/////' },
])(`makes url %p`, queryParams => {
expect(Linking.makeUrl('some/path', queryParams)).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`makeUrl queries makes url {"emptyParam": ""} 1`] = `"exp://exp.host/@test/test/--/some/path?emptyParam="`;

exports[`makeUrl queries makes url {"escapePluses": "email+with+plus@whatever.com"} 1`] = `"exp://exp.host/@test/test/--/some/path?escapePluses=email%252Bwith%252Bplus%2540whatever.com"`;

exports[`makeUrl queries makes url {"lotsOfSlashes": "/////"} 1`] = `"exp://exp.host/@test/test/--/some/path?lotsOfSlashes=%252F%252F%252F%252F%252F"`;

exports[`makeUrl queries makes url {"shouldEscape": "%2b%20"} 1`] = `"exp://exp.host/@test/test/--/some/path?shouldEscape=%25252b%252520"`;

exports[`makeUrl queries makes url {"undefinedParam": undefined} 1`] = `"exp://exp.host/@test/test/--/some/path"`;

exports[`parse parses "custom://" 1`] = `
Object {
"hostname": null,
Expand All @@ -18,6 +28,17 @@ Object {
}
`;

exports[`parse parses "custom:///?shouldBeEscaped=x%252By%2540xxx.com" 1`] = `
Object {
"hostname": null,
"path": "",
"queryParams": Object {
"shouldBeEscaped": "x+y@xxx.com",
},
"scheme": "custom",
}
`;

exports[`parse parses "custom:///test/path?foo=bar" 1`] = `
Object {
"hostname": null,
Expand Down Expand Up @@ -100,6 +121,28 @@ Object {
}
`;

exports[`parse parses "https://example.com/test/path?missingQueryValue=" 1`] = `
Object {
"hostname": "example.com",
"path": "test/path",
"queryParams": Object {
"missingQueryValue": "",
},
"scheme": "https",
}
`;

exports[`parse parses "https://example.com/test/path?query=do+not+escape" 1`] = `
Object {
"hostname": "example.com",
"path": "test/path",
"queryParams": Object {
"query": "do not escape",
},
"scheme": "https",
}
`;

exports[`parse parses "https://example.com/test/path?query=param" 1`] = `
Object {
"hostname": "example.com",
Expand Down
43 changes: 43 additions & 0 deletions packages/expo/src/__tests__/__snapshots__/Linking-test.ts.snap.ios
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`makeUrl queries makes url {"emptyParam": ""} 1`] = `"exp://exp.host/@test/test/--/some/path?emptyParam="`;

exports[`makeUrl queries makes url {"escapePluses": "email+with+plus@whatever.com"} 1`] = `"exp://exp.host/@test/test/--/some/path?escapePluses=email%252Bwith%252Bplus%2540whatever.com"`;

exports[`makeUrl queries makes url {"lotsOfSlashes": "/////"} 1`] = `"exp://exp.host/@test/test/--/some/path?lotsOfSlashes=%252F%252F%252F%252F%252F"`;

exports[`makeUrl queries makes url {"shouldEscape": "%2b%20"} 1`] = `"exp://exp.host/@test/test/--/some/path?shouldEscape=%25252b%252520"`;

exports[`makeUrl queries makes url {"undefinedParam": undefined} 1`] = `"exp://exp.host/@test/test/--/some/path"`;

exports[`parse parses "custom://" 1`] = `
Object {
"hostname": null,
Expand All @@ -18,6 +28,17 @@ Object {
}
`;

exports[`parse parses "custom:///?shouldBeEscaped=x%252By%2540xxx.com" 1`] = `
Object {
"hostname": null,
"path": "",
"queryParams": Object {
"shouldBeEscaped": "x+y@xxx.com",
},
"scheme": "custom",
}
`;

exports[`parse parses "custom:///test/path?foo=bar" 1`] = `
Object {
"hostname": null,
Expand Down Expand Up @@ -100,6 +121,28 @@ Object {
}
`;

exports[`parse parses "https://example.com/test/path?missingQueryValue=" 1`] = `
Object {
"hostname": "example.com",
"path": "test/path",
"queryParams": Object {
"missingQueryValue": "",
},
"scheme": "https",
}
`;

exports[`parse parses "https://example.com/test/path?query=do+not+escape" 1`] = `
Object {
"hostname": "example.com",
"path": "test/path",
"queryParams": Object {
"query": "do not escape",
},
"scheme": "https",
}
`;

exports[`parse parses "https://example.com/test/path?query=param" 1`] = `
Object {
"hostname": "example.com",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`makeUrl queries makes url {"emptyParam": ""} 1`] = `"exp://some/path?emptyParam="`;

exports[`makeUrl queries makes url {"escapePluses": "email+with+plus@whatever.com"} 1`] = `"exp://some/path?escapePluses=email%252Bwith%252Bplus%2540whatever.com"`;

exports[`makeUrl queries makes url {"lotsOfSlashes": "/////"} 1`] = `"exp://some/path?lotsOfSlashes=%252F%252F%252F%252F%252F"`;

exports[`makeUrl queries makes url {"shouldEscape": "%2b%20"} 1`] = `"exp://some/path?shouldEscape=%25252b%252520"`;

exports[`makeUrl queries makes url {"undefinedParam": undefined} 1`] = `"exp://some/path"`;

exports[`parse parses "custom://" 1`] = `
Object {
"hostname": null,
Expand All @@ -18,6 +28,17 @@ Object {
}
`;

exports[`parse parses "custom:///?shouldBeEscaped=x%252By%2540xxx.com" 1`] = `
Object {
"hostname": null,
"path": "",
"queryParams": Object {
"shouldBeEscaped": "x+y@xxx.com",
},
"scheme": "custom",
}
`;

exports[`parse parses "custom:///test/path?foo=bar" 1`] = `
Object {
"hostname": null,
Expand Down Expand Up @@ -100,6 +121,28 @@ Object {
}
`;

exports[`parse parses "https://example.com/test/path?missingQueryValue=" 1`] = `
Object {
"hostname": "example.com",
"path": "test/path",
"queryParams": Object {
"missingQueryValue": "",
},
"scheme": "https",
}
`;

exports[`parse parses "https://example.com/test/path?query=do+not+escape" 1`] = `
Object {
"hostname": "example.com",
"path": "test/path",
"queryParams": Object {
"query": "do not escape",
},
"scheme": "https",
}
`;

exports[`parse parses "https://example.com/test/path?query=param" 1`] = `
Object {
"hostname": "example.com",
Expand Down
43 changes: 43 additions & 0 deletions packages/expo/src/__tests__/__snapshots__/Linking-test.ts.snap.web
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`makeUrl queries makes url {"emptyParam": ""} 1`] = `"exp://localhost/some/path?emptyParam="`;

exports[`makeUrl queries makes url {"escapePluses": "email+with+plus@whatever.com"} 1`] = `"exp://localhost/some/path?escapePluses=email%252Bwith%252Bplus%2540whatever.com"`;

exports[`makeUrl queries makes url {"lotsOfSlashes": "/////"} 1`] = `"exp://localhost/some/path?lotsOfSlashes=%252F%252F%252F%252F%252F"`;

exports[`makeUrl queries makes url {"shouldEscape": "%2b%20"} 1`] = `"exp://localhost/some/path?shouldEscape=%25252b%252520"`;

exports[`makeUrl queries makes url {"undefinedParam": undefined} 1`] = `"exp://localhost/some/path"`;

exports[`parse parses "custom://" 1`] = `
Object {
"hostname": null,
Expand All @@ -18,6 +28,17 @@ Object {
}
`;

exports[`parse parses "custom:///?shouldBeEscaped=x%252By%2540xxx.com" 1`] = `
Object {
"hostname": null,
"path": "",
"queryParams": Object {
"shouldBeEscaped": "x+y@xxx.com",
},
"scheme": "custom",
}
`;

exports[`parse parses "custom:///test/path?foo=bar" 1`] = `
Object {
"hostname": null,
Expand Down Expand Up @@ -100,6 +121,28 @@ Object {
}
`;

exports[`parse parses "https://example.com/test/path?missingQueryValue=" 1`] = `
Object {
"hostname": "example.com",
"path": "test/path",
"queryParams": Object {
"missingQueryValue": "",
},
"scheme": "https",
}
`;

exports[`parse parses "https://example.com/test/path?query=do+not+escape" 1`] = `
Object {
"hostname": "example.com",
"path": "test/path",
"queryParams": Object {
"query": "do not escape",
},
"scheme": "https",
}
`;

exports[`parse parses "https://example.com/test/path?query=param" 1`] = `
Object {
"hostname": "example.com",
Expand Down

0 comments on commit e50f4c3

Please sign in to comment.