better support variations

This commit is contained in:
Caleb Roseland 2023-10-23 17:25:28 -05:00
parent fc7d8a3d08
commit 03ccfda514
2 changed files with 8 additions and 8 deletions

View file

@ -118,12 +118,7 @@ export function parseDeepLink(deepLinkUrl: string): DeepLinkWithData {
try {
const url = removeProtocol(decodeURIComponent(deepLinkUrl));
if (
url.includes('../') ||
url.includes('/..') ||
url.includes('..%2f') ||
url.includes('%2f..')
) {
if (isDeepLinkInvalid(url)) {
return {type: DeepLink.Invalid, url: deepLinkUrl};
}
@ -158,6 +153,11 @@ export function parseDeepLink(deepLinkUrl: string): DeepLinkWithData {
return {type: DeepLink.Invalid, url: deepLinkUrl};
}
function isDeepLinkInvalid(decodedUrl: string) {
const url = decodeURIComponent(decodedUrl);
return url.includes('../') || url.includes('/..');
}
export function matchDeepLink(url?: string, serverURL?: string, siteURL?: string) {
if (!url || (!serverURL && !siteURL)) {
return '';

View file

@ -196,9 +196,9 @@ describe('UrlUtils', () => {
expected: {type: DeepLinkType.Invalid},
},
{
name: 'should return null for encoded invalid deeplink',
name: 'should return null for double encoded invalid deeplink',
input: {
url: DEEPLINK_URL_ROOT + '/ad-1/channels/%252f..%252ftown-square',
url: DEEPLINK_URL_ROOT + '/ad-1/channels/%252f%252e.town-square',
serverURL: SERVER_URL,
siteURL: SITE_URL,
},