mirror of
https://github.com/outline/outline.git
synced 2026-11-22 14:01:41 +03:00
fix: Anchor with some UTF8 characters not correctly decoding (#9778)
This commit is contained in:
1 parent
3f4950031b
commit
481adc6ecb
2 files changed
+51
-1
No files matched your search
@@ -10,4 +10,54 @@ describe("decodeURIComponentSafe", () => {
|
||||
expect(decodeURIComponentSafe("%7D")).toBe("}");
|
||||
expect(decodeURIComponentSafe("%2F")).toBe("/");
|
||||
});
|
||||
|
||||
test("to handle malformed percent encoding", () => {
|
||||
// Single % at end of string
|
||||
expect(decodeURIComponentSafe("test%")).toBe("test%");
|
||||
|
||||
// % followed by single hex digit
|
||||
expect(decodeURIComponentSafe("test%A")).toBe("test%A");
|
||||
|
||||
// % followed by non-hex characters
|
||||
expect(decodeURIComponentSafe("test%GG")).toBe("test%GG");
|
||||
expect(decodeURIComponentSafe("test%XY")).toBe("test%XY");
|
||||
|
||||
// % followed by space
|
||||
expect(decodeURIComponentSafe("test% ")).toBe("test% ");
|
||||
|
||||
// Multiple malformed % symbols
|
||||
expect(decodeURIComponentSafe("%test%")).toBe("%test%");
|
||||
expect(decodeURIComponentSafe("%A%B")).toBe("%A%B");
|
||||
});
|
||||
|
||||
test("to handle mixed valid and invalid percent encoding", () => {
|
||||
// Valid encoding mixed with invalid
|
||||
expect(decodeURIComponentSafe("%20test%")).toBe(" test%");
|
||||
expect(decodeURIComponentSafe("%7D%invalid")).toBe("}%invalid");
|
||||
expect(decodeURIComponentSafe("valid%20%")).toBe("valid %");
|
||||
|
||||
// Complex mixed case
|
||||
expect(decodeURIComponentSafe("%20%A%2F%")).toBe(" %A/%");
|
||||
});
|
||||
|
||||
test("to handle edge cases", () => {
|
||||
// Empty string
|
||||
expect(decodeURIComponentSafe("")).toBe("");
|
||||
|
||||
// Only % symbols
|
||||
expect(decodeURIComponentSafe("%%%")).toBe("%%%");
|
||||
|
||||
// Language specific characters
|
||||
expect(decodeURIComponentSafe("%E3%81%AB%E3%81%BB%E3%82%93%E3%81%94")).toBe(
|
||||
"にほんご"
|
||||
);
|
||||
|
||||
// % at various positions
|
||||
expect(decodeURIComponentSafe("%start")).toBe("%start");
|
||||
expect(decodeURIComponentSafe("mid%dle")).toBe("mid%dle");
|
||||
expect(decodeURIComponentSafe("end%")).toBe("end%");
|
||||
|
||||
// Already encoded %25 should decode to %
|
||||
expect(decodeURIComponentSafe("%25%25")).toBe("%%");
|
||||
});
|
||||
});
|
||||
+1
-1
@@ -30,7 +30,7 @@ export function isHash(href: string) {
|
||||
export function decodeURIComponentSafe(text: string) {
|
||||
try {
|
||||
return text
|
||||
? decodeURIComponent(text.replace(/%(?![0-9][0-9a-fA-F]+)/g, "%25"))
|
||||
? decodeURIComponent(text.replace(/%(?![0-9a-fA-F]{2})/g, "%25"))
|
||||
: text;
|
||||
} catch (_) {
|
||||
return text;
|
||||
|
||||
Reference in new issue
Block a user