Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/sim/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ export function match(
"?": query = "*",
"#": fragment = "*",
caseSensitive = true,
percentEncoded: _ = true, // TODO: Handle percentEncoded
percentEncoded = true,
} = components;
const urlPathname = url.pathname;
const urlFragment = url.hash.slice(1);
const urlQuery = url.search.slice(1);
let urlPathname = url.pathname;
let urlFragment = url.hash.slice(1);
let urlQuery = url.search.slice(1);

if (percentEncoded) {
urlPathname = decodeURIComponent(urlPathname);
urlFragment = decodeURIComponent(urlFragment);
urlQuery = decodeURIComponent(urlQuery);
}
if (!stringToRegex(fragment, caseSensitive).test(urlFragment)) return false;
if (!stringToRegex(path, caseSensitive).test(urlPathname)) return false;
if (typeof query === "string") {
Expand Down
11 changes: 11 additions & 0 deletions tests/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,14 @@ it("should handle multiple details", async () => {
assert.deepStrictEqual(await verify(json, path), expected);
assert.deepStrictEqual(await verifySim(json, path), expected);
});

it("should handle percentEncoded", async () => {
const json = fromDetails({
appID: "HOGE.com.example.app",
components: [{ "/": "/search/", percentEncoded: true }],
});
const path = "/search/%2F";
const expected = new Map();
assert.deepStrictEqual(await verify(json, path), expected);
assert.deepStrictEqual(await verifySim(json, path), expected);
});