Ensure no params are getting lowercased
This commit is contained in:
parent
31d680d194
commit
5c62fa0a14
2 changed files with 51 additions and 42 deletions
|
@ -36,6 +36,9 @@ describe('signalRoutes', () => {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const foo = 'FoO.bAr-BaZ_123/456';
|
||||||
|
const fooNoSlash = 'FoO.bAr-BaZ_123';
|
||||||
|
|
||||||
it('nonsense', () => {
|
it('nonsense', () => {
|
||||||
const check = createCheck({
|
const check = createCheck({
|
||||||
isRoute: false,
|
isRoute: false,
|
||||||
|
@ -72,42 +75,42 @@ describe('signalRoutes', () => {
|
||||||
it('contactByEncryptedUsername', () => {
|
it('contactByEncryptedUsername', () => {
|
||||||
const result: ParsedSignalRoute = {
|
const result: ParsedSignalRoute = {
|
||||||
key: 'contactByEncryptedUsername',
|
key: 'contactByEncryptedUsername',
|
||||||
args: { encryptedUsername: 'foobar' },
|
args: { encryptedUsername: foo },
|
||||||
};
|
};
|
||||||
const check = createCheck();
|
const check = createCheck();
|
||||||
check('https://signal.me/#eu/foobar', result);
|
check(`https://signal.me/#eu/${foo}`, result);
|
||||||
check('https://signal.me#eu/foobar', result);
|
check(`https://signal.me#eu/${foo}`, result);
|
||||||
check('sgnl://signal.me/#eu/foobar', result);
|
check(`sgnl://signal.me/#eu/${foo}`, result);
|
||||||
check('sgnl://signal.me#eu/foobar', result);
|
check(`sgnl://signal.me#eu/${foo}`, result);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('groupInvites', () => {
|
it('groupInvites', () => {
|
||||||
const result: ParsedSignalRoute = {
|
const result: ParsedSignalRoute = {
|
||||||
key: 'groupInvites',
|
key: 'groupInvites',
|
||||||
args: { inviteCode: 'foobar' },
|
args: { inviteCode: fooNoSlash },
|
||||||
};
|
};
|
||||||
const check = createCheck();
|
const check = createCheck();
|
||||||
check('https://signal.group/#foobar', result);
|
check(`https://signal.group/#${fooNoSlash}`, result);
|
||||||
check('https://signal.group#foobar', result);
|
check(`https://signal.group#${fooNoSlash}`, result);
|
||||||
check('sgnl://signal.group/#foobar', result);
|
check(`sgnl://signal.group/#${fooNoSlash}`, result);
|
||||||
check('sgnl://signal.group#foobar', result);
|
check(`sgnl://signal.group#${fooNoSlash}`, result);
|
||||||
check('sgnl://joingroup/#foobar', result);
|
check(`sgnl://joingroup/#${fooNoSlash}`, result);
|
||||||
check('sgnl://joingroup#foobar', result);
|
check(`sgnl://joingroup#${fooNoSlash}`, result);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('linkDevice', () => {
|
it('linkDevice', () => {
|
||||||
const result: ParsedSignalRoute = {
|
const result: ParsedSignalRoute = {
|
||||||
key: 'linkDevice',
|
key: 'linkDevice',
|
||||||
args: { uuid: 'foo', pubKey: 'bar' },
|
args: { uuid: foo, pubKey: foo },
|
||||||
};
|
};
|
||||||
const check = createCheck({ hasWebUrl: false });
|
const check = createCheck({ hasWebUrl: false });
|
||||||
check('sgnl://linkdevice/?uuid=foo&pub_key=bar', result);
|
check(`sgnl://linkdevice/?uuid=${foo}&pub_key=${foo}`, result);
|
||||||
check('sgnl://linkdevice?uuid=foo&pub_key=bar', result);
|
check(`sgnl://linkdevice?uuid=${foo}&pub_key=${foo}`, result);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('captcha', () => {
|
it('captcha', () => {
|
||||||
const captchaId =
|
const captchaId =
|
||||||
'signal-hcaptcha.foo-bar_baz.challenge.foo-bar_baz.foo-bar_baz';
|
'signal-hcaptcha.Foo-bAr_baz.challenge.fOo-bAR_baZ.fOO-BaR_baz';
|
||||||
const result: ParsedSignalRoute = {
|
const result: ParsedSignalRoute = {
|
||||||
key: 'captcha',
|
key: 'captcha',
|
||||||
args: { captchaId },
|
args: { captchaId },
|
||||||
|
@ -119,53 +122,59 @@ describe('signalRoutes', () => {
|
||||||
it('linkCall', () => {
|
it('linkCall', () => {
|
||||||
const result: ParsedSignalRoute = {
|
const result: ParsedSignalRoute = {
|
||||||
key: 'linkCall',
|
key: 'linkCall',
|
||||||
args: { key: 'foobar' },
|
args: { key: foo },
|
||||||
};
|
};
|
||||||
const check = createCheck();
|
const check = createCheck();
|
||||||
check('https://signal.link/call/#key=foobar', result);
|
check(`https://signal.link/call/#key=${foo}`, result);
|
||||||
check('https://signal.link/call#key=foobar', result);
|
check(`https://signal.link/call#key=${foo}`, result);
|
||||||
check('sgnl://signal.link/call/#key=foobar', result);
|
check(`sgnl://signal.link/call/#key=${foo}`, result);
|
||||||
check('sgnl://signal.link/call#key=foobar', result);
|
check(`sgnl://signal.link/call#key=${foo}`, result);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('artAuth', () => {
|
it('artAuth', () => {
|
||||||
const result: ParsedSignalRoute = {
|
const result: ParsedSignalRoute = {
|
||||||
key: 'artAuth',
|
key: 'artAuth',
|
||||||
args: { token: 'foo', pubKey: 'bar' },
|
args: { token: foo, pubKey: foo },
|
||||||
};
|
};
|
||||||
const check = createCheck({ hasWebUrl: false });
|
const check = createCheck({ hasWebUrl: false });
|
||||||
check('sgnl://art-auth/?token=foo&pub_key=bar', result);
|
check(`sgnl://art-auth/?token=${foo}&pub_key=${foo}`, result);
|
||||||
check('sgnl://art-auth?token=foo&pub_key=bar', result);
|
check(`sgnl://art-auth?token=${foo}&pub_key=${foo}`, result);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('artAddStickers', () => {
|
it('artAddStickers', () => {
|
||||||
const result: ParsedSignalRoute = {
|
const result: ParsedSignalRoute = {
|
||||||
key: 'artAddStickers',
|
key: 'artAddStickers',
|
||||||
args: { packId: 'foo', packKey: 'bar' },
|
args: { packId: foo, packKey: foo },
|
||||||
};
|
};
|
||||||
const check = createCheck();
|
const check = createCheck();
|
||||||
check('https://signal.art/addstickers/#pack_id=foo&pack_key=bar', result);
|
check(
|
||||||
check('https://signal.art/addstickers#pack_id=foo&pack_key=bar', result);
|
`https://signal.art/addstickers/#pack_id=${foo}&pack_key=${foo}`,
|
||||||
check('sgnl://addstickers/?pack_id=foo&pack_key=bar', result);
|
result
|
||||||
check('sgnl://addstickers?pack_id=foo&pack_key=bar', result);
|
);
|
||||||
|
check(
|
||||||
|
`https://signal.art/addstickers#pack_id=${foo}&pack_key=${foo}`,
|
||||||
|
result
|
||||||
|
);
|
||||||
|
check(`sgnl://addstickers/?pack_id=${foo}&pack_key=${foo}`, result);
|
||||||
|
check(`sgnl://addstickers?pack_id=${foo}&pack_key=${foo}`, result);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('showConversation', () => {
|
it('showConversation', () => {
|
||||||
const check = createCheck({ isRoute: true, hasWebUrl: false });
|
const check = createCheck({ isRoute: true, hasWebUrl: false });
|
||||||
const args1 = 'conversationId=abc';
|
const args1 = `conversationId=${foo}`;
|
||||||
const args2 = 'conversationId=abc&messageId=def';
|
const args2 = `conversationId=${foo}&messageId=${foo}`;
|
||||||
const args3 = 'conversationId=abc&messageId=def&storyId=ghi';
|
const args3 = `conversationId=${foo}&messageId=${foo}&storyId=${foo}`;
|
||||||
const result1: ParsedSignalRoute = {
|
const result1: ParsedSignalRoute = {
|
||||||
key: 'showConversation',
|
key: 'showConversation',
|
||||||
args: { conversationId: 'abc', messageId: null, storyId: null },
|
args: { conversationId: foo, messageId: null, storyId: null },
|
||||||
};
|
};
|
||||||
const result2: ParsedSignalRoute = {
|
const result2: ParsedSignalRoute = {
|
||||||
key: 'showConversation',
|
key: 'showConversation',
|
||||||
args: { conversationId: 'abc', messageId: 'def', storyId: null },
|
args: { conversationId: foo, messageId: foo, storyId: null },
|
||||||
};
|
};
|
||||||
const result3: ParsedSignalRoute = {
|
const result3: ParsedSignalRoute = {
|
||||||
key: 'showConversation',
|
key: 'showConversation',
|
||||||
args: { conversationId: 'abc', messageId: 'def', storyId: 'ghi' },
|
args: { conversationId: foo, messageId: foo, storyId: foo },
|
||||||
};
|
};
|
||||||
check(`sgnl://show-conversation/?${args1}`, result1);
|
check(`sgnl://show-conversation/?${args1}`, result1);
|
||||||
check(`sgnl://show-conversation?${args1}`, result1);
|
check(`sgnl://show-conversation?${args1}`, result1);
|
||||||
|
@ -178,11 +187,11 @@ describe('signalRoutes', () => {
|
||||||
it('startCallLobby', () => {
|
it('startCallLobby', () => {
|
||||||
const result: ParsedSignalRoute = {
|
const result: ParsedSignalRoute = {
|
||||||
key: 'startCallLobby',
|
key: 'startCallLobby',
|
||||||
args: { conversationId: 'abc' },
|
args: { conversationId: foo },
|
||||||
};
|
};
|
||||||
const check = createCheck({ isRoute: true, hasWebUrl: false });
|
const check = createCheck({ isRoute: true, hasWebUrl: false });
|
||||||
check('sgnl://start-call-lobby/?conversationId=abc', result);
|
check(`sgnl://start-call-lobby/?conversationId=${foo}`, result);
|
||||||
check('sgnl://start-call-lobby?conversationId=abc', result);
|
check(`sgnl://start-call-lobby?conversationId=${foo}`, result);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('showWindow', () => {
|
it('showWindow', () => {
|
||||||
|
|
|
@ -110,7 +110,7 @@ type PartialNullable<T> = {
|
||||||
type RouteConfig<Args extends object> = {
|
type RouteConfig<Args extends object> = {
|
||||||
patterns: Array<URLMatcher>;
|
patterns: Array<URLMatcher>;
|
||||||
schema: z.ZodType<Args>;
|
schema: z.ZodType<Args>;
|
||||||
parse(result: URLPatternResult): PartialNullable<Args>;
|
parse(result: URLPatternResult, url: URL): PartialNullable<Args>;
|
||||||
toWebUrl?(args: Args): URL;
|
toWebUrl?(args: Args): URL;
|
||||||
toAppUrl?(args: Args): URL;
|
toAppUrl?(args: Args): URL;
|
||||||
};
|
};
|
||||||
|
@ -154,7 +154,7 @@ function _route<Key extends string, Args extends object>(
|
||||||
if (result) {
|
if (result) {
|
||||||
return {
|
return {
|
||||||
key,
|
key,
|
||||||
args: config.schema.parse(config.parse(result)),
|
args: config.schema.parse(config.parse(result, url)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -330,9 +330,9 @@ export const captchaRoute = _route('captcha', {
|
||||||
schema: z.object({
|
schema: z.object({
|
||||||
captchaId: paramSchema, // opaque
|
captchaId: paramSchema, // opaque
|
||||||
}),
|
}),
|
||||||
parse(result) {
|
parse(_result, url) {
|
||||||
return {
|
return {
|
||||||
captchaId: result.hostname.groups.captchaId,
|
captchaId: url.hostname,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
toAppUrl(args) {
|
toAppUrl(args) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue