Skip to content

Commit 89e8d10

Browse files
committed
👍 Use UppserCase in percent encoded characters
While `URL` or `URLSearchParams` use UppserCase.
1 parent 8fb0b24 commit 89e8d10

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

denops_std/bufname/bufname.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function format({ scheme, path, params, fragment }: Bufname): string {
3535
`Scheme '${scheme}' contains unusable characters. Only alphabets are allowed.`,
3636
);
3737
}
38-
const encodedPath = encode(path).replaceAll(";", "%3b").replaceAll(
38+
const encodedPath = encode(path).replaceAll(";", "%3B").replaceAll(
3939
"#",
4040
"%23",
4141
);
@@ -68,7 +68,7 @@ export function parse(expr: string): Bufname {
6868
);
6969
}
7070
const remain = decode(expr.substring(`${scheme}://`.length), [
71-
"%3b", // ;
71+
"%3B", // ;
7272
"%23", // #
7373
]);
7474
const m2 = remain.match(pathPattern)!;

denops_std/bufname/bufname_test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Deno.test("format encodes unusable characters in 'path'", () => {
6363
path: "/<>|?*",
6464
};
6565
const dst = format(src);
66-
const exp = "denops:///%3c%3e%7c%3f%2a";
66+
const exp = "denops:///%3C%3E%7C%3F%2A";
6767
assertEquals(dst, exp);
6868
});
6969
Deno.test("format returns buffer name string from Bufname instance (with URLSearchParams)", () => {
@@ -89,7 +89,7 @@ Deno.test("format encodes unusable characters in 'params'", () => {
8989
},
9090
};
9191
const dst = format(src);
92-
const exp = "denops:///absolute/path/to/worktree;foo=%3C%3E%7C%3F%2a";
92+
const exp = "denops:///absolute/path/to/worktree;foo=%3C%3E%7C%3F%2A";
9393
assertEquals(dst, exp);
9494
});
9595
Deno.test("format returns buffer name string from Bufname instance (with fragment)", () => {
@@ -109,7 +109,7 @@ Deno.test("format encodes unusable characters in 'fragment'", () => {
109109
fragment: "<>|?*",
110110
};
111111
const dst = format(src);
112-
const exp = "denops:///absolute/path/to/worktree#%3c%3e%7c%3f%2a";
112+
const exp = "denops:///absolute/path/to/worktree#%3C%3E%7C%3F%2A";
113113
assertEquals(dst, exp);
114114
});
115115
Deno.test("format returns buffer name string from Bufname instance (with URLSearchParams and fragment)", () => {
@@ -134,7 +134,7 @@ Deno.test("format encodes ';' and '#' in 'path'", () => {
134134
path: "/hello;world#hello",
135135
};
136136
const dst = format(src);
137-
const exp = "denops:///hello%3bworld%23hello";
137+
const exp = "denops:///hello%3Bworld%23hello";
138138
assertEquals(dst, exp);
139139
});
140140

@@ -185,7 +185,7 @@ Deno.test("parse returns Bufname instance from buffer name", () => {
185185
assertEquals(dst, exp);
186186
});
187187
Deno.test("parse decodes percent-encoded characters in 'path'", () => {
188-
const src = "denops:///%3c%3e%7c%3f%2a";
188+
const src = "denops:///%3C%3E%7C%3F%2A";
189189
const dst = parse(src);
190190
const exp = {
191191
scheme: "denops",
@@ -207,7 +207,7 @@ Deno.test("parse returns Bufname instance from buffer name (with params)", () =>
207207
assertEquals(dst, exp);
208208
});
209209
Deno.test("parse decodes percent-encoded characters in 'params'", () => {
210-
const src = "denops:///absolute/path/to/worktree;foo=%3C%3E%7C%3F%2a";
210+
const src = "denops:///absolute/path/to/worktree;foo=%3C%3E%7C%3F%2A";
211211
const dst = parse(src);
212212
const exp = {
213213
scheme: "denops",
@@ -229,7 +229,7 @@ Deno.test("parse returns Bufname instance from buffer name (with fragment)", ()
229229
assertEquals(dst, exp);
230230
});
231231
Deno.test("parse decodes percent-encoded characters in 'fragment'", () => {
232-
const src = "denops:///absolute/path/to/worktree#%3c%3e%7c%3f%2a";
232+
const src = "denops:///absolute/path/to/worktree#%3C%3E%7C%3F%2A";
233233
const dst = parse(src);
234234
const exp = {
235235
scheme: "denops",
@@ -254,7 +254,7 @@ Deno.test("parse returns Bufname instance from buffer name (with params and frag
254254
assertEquals(dst, exp);
255255
});
256256
Deno.test("parse decode percent-encoded characters (';' and '#') in 'path'", () => {
257-
const src = "denops:///hello%3bworld%23hello";
257+
const src = "denops:///hello%3Bworld%23hello";
258258
const dst = parse(src);
259259
const exp = {
260260
scheme: "denops",

denops_std/bufname/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const encodedCharacterPattern = /(?:%[0-9a-fA-F]{2})+/g;
1010
export function encode(expr: string): string {
1111
expr = expr.replaceAll(
1212
bufnameUnusablePattern,
13-
(c) => `%${c.codePointAt(0)!.toString(16)}`,
13+
(c) => `%${c.codePointAt(0)!.toString(16).toUpperCase()}`,
1414
);
1515
return expr;
1616
}
@@ -19,10 +19,11 @@ export function encode(expr: string): string {
1919
* Decode all percent-encoded characters.
2020
*/
2121
export function decode(expr: string, excludes?: string[]): string {
22+
excludes = (excludes ?? []).map((v) => v.toUpperCase());
2223
expr = expr.replaceAll(
2324
encodedCharacterPattern,
2425
(m) => {
25-
if (excludes?.includes(m.toLowerCase())) {
26+
if (excludes?.includes(m.toUpperCase())) {
2627
return m;
2728
}
2829
return decodeURIComponent(m);

denops_std/bufname/utils_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Deno.test("encode does nothing on numeric characters", () => {
1616
Deno.test('encode encodes some symbol characters ("<>|?*)', () => {
1717
const src = " !\"#$%&'()*+,-./:;<=>?@[\\]^`{|}~";
1818
const dst = encode(src);
19-
const exp = " !%22#$%&'()%2a+,-./:;%3c=%3e%3f@[\\]^`{%7c}~";
19+
const exp = " !%22#$%&'()%2A+,-./:;%3C=%3E%3F@[\\]^`{%7C}~";
2020
assertEquals(dst, exp);
2121
});
2222
Deno.test("encode does nothing on 日本語", () => {
@@ -45,7 +45,7 @@ Deno.test("decode does nothing on numeric characters", () => {
4545
assertEquals(dst, exp);
4646
});
4747
Deno.test('decode decodes encoded characters ("<>|?*)', () => {
48-
const src = " !%22#$%&'()%2a+,-./:;%3c=%3e%3f@[\\]^`{%7c}~";
48+
const src = " !%22#$%&'()%2A+,-./:;%3C=%3E%3F@[\\]^`{%7C}~";
4949
const dst = decode(src);
5050
const exp = " !\"#$%&'()*+,-./:;<=>?@[\\]^`{|}~";
5151
assertEquals(dst, exp);

0 commit comments

Comments
 (0)