Skip to content

Commit

Permalink
fix(sanitizeURIComponent): sanitize url escaping (#137)
Browse files Browse the repository at this point in the history
* fix(sanitizeURIComponent): sanitize url escaping

* chore: format
  • Loading branch information
antfu committed Jan 9, 2023
1 parent 3531dcd commit f91da0d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/utils.ts
Expand Up @@ -14,7 +14,9 @@ export function fileURLToPath(id: string): string {
const INVALID_CHAR_RE = /[\u0000-\u001F"#$&*+,/:;<=>?@[\]^`{|}\u007F]+/g;

export function sanitizeURIComponent(name = "", replacement = "_"): string {
return name.replace(INVALID_CHAR_RE, replacement);
return name
.replace(INVALID_CHAR_RE, replacement)
.replace(/%../g, replacement);
}

export function sanitizeFilePath(filePath = "") {
Expand Down
2 changes: 2 additions & 0 deletions test/utils.test.ts
Expand Up @@ -30,6 +30,8 @@ describe("sanitizeFilePath", () => {
"/te#st/[].jsx": "/te_st/_.jsx",
'\0a?b*c:d\u007Fe<f>g#h"i{j}k|l^m[n]o`p.jsx':
"_a_b_c_d_e_f_g_h_i_j_k_l_m_n_o_p.jsx",
"Foo.vue?vue&type=script&setup=true&generic=T%20extends%20any%2C%20O%20extends%20T%3CZ%7Ca%3E&lang":
"Foo.vue_vue_type_script_setup_true_generic_T_extends_any__O_extends_T_Z_a__lang",
"": "",
};
for (const id in cases) {
Expand Down

0 comments on commit f91da0d

Please sign in to comment.