Skip to content

Commit

Permalink
fix(mdw): always correct the input format in Firebase DL middleware (…
Browse files Browse the repository at this point in the history
…to simplify Firebase whitelist patterns)
  • Loading branch information
sneko committed Jun 23, 2022
1 parent f4d57ac commit 07320d1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/middlewares/format-firebase-dynamic-links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function FormatFirebaseDynamicLinksMiddleware(
let iosStoreUrl: URL | undefined;

const dynamicLink = new URL(options.dynamicLinkBase);
dynamicLink.searchParams.set('link', properties.href);
dynamicLink.searchParams.set('link', url.toString());

if (options.android) {
dynamicLink.searchParams.set('apn', options.android.storeId);
Expand Down
21 changes: 19 additions & 2 deletions test/middlewares/global.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ describe('Middlewares', () => {
const properties = mdwComposition.apply(initialProperties);

expect(properties.href).toBe(
'http://example.page.link/?link=https%3A%2F%2Fexample.com'
'http://example.page.link/?link=https%3A%2F%2Fexample.com%2F'
);
});

Expand All @@ -210,7 +210,7 @@ describe('Middlewares', () => {
const properties = mdwComposition.apply(initialProperties);
const dynamicLink = new URL(properties.href);

expect(dynamicLink.searchParams.get('link')).toBe('https://example.com');
expect(dynamicLink.searchParams.get('link')).toBe('https://example.com/');
expect(dynamicLink.searchParams.get('apn')).toBe('test_android_1');
expect(dynamicLink.searchParams.get('ibi')).toBe('test_ios_1');
expect(dynamicLink.searchParams.get('isi')).toBe('test_ios_2');
Expand Down Expand Up @@ -320,5 +320,22 @@ describe('Middlewares', () => {

expect(dynamicLink.searchParams.get('efr')).toBe('1');
});

it('should correct the input format (to simplify Firebase URL patterns to whitelist)', () => {
initialProperties.href = 'https://example.com?param=1';

mdwComposition.add(
FormatFirebaseDynamicLinksMiddleware({
dynamicLinkBase: 'http://example.page.link',
})
);

const properties = mdwComposition.apply(initialProperties);

const url = new URL(properties.href);
const originalLink = url.searchParams.get('link');

expect(originalLink).toBe('https://example.com/?param=1');
});
});
});

0 comments on commit 07320d1

Please sign in to comment.