Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
18 changes: 14 additions & 4 deletions src/sim/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@ export function match(
"?": query = "*",
"#": fragment = "*",
caseSensitive = true,
percentEncoded: _ = true, // TODO: Handle percentEncoded
percentEncoded = true,
// percentEncoded: _ = true, // TODO: Handle percentEncoded
} = components;
const urlPathname = url.pathname;
const urlFragment = url.hash.slice(1);
const urlQuery = url.search.slice(1);

// 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
12 changes: 12 additions & 0 deletions tests/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,15 @@ it("should handle multiple details", async () => {
assert.deepStrictEqual(await verify(json, path), expected);
assert.deepStrictEqual(await verifySim(json, path), expected);
});

// TODO: verifyとverifySimの挙動が異なるので挙動をあわせる
it("should handle percentEncoded false with Unicode", async () => {
const json = fromDetails({
appID: "HOGE.com.example.app",
components: [{ "/": "/search/🌟", percentEncoded: true }],
});
const path = "/search/%F0%9F%8C%9F"; // Unicode "🌟" のパーセントエンコード表現
const expected = new Map();
assert.deepStrictEqual(await verify(json, path), expected);
assert.deepStrictEqual(await verifySim(json, path), expected);
});
Loading