Skip to content

Commit

Permalink
fix: path should be unescaped (#958)
Browse files Browse the repository at this point in the history
* fix: path should be unescaped

* chore: code style
  • Loading branch information
sorrycc authored Mar 18, 2024
1 parent 506a462 commit 17259de
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 10 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions crates/mako/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ path = "src/main.rs"
test = false

[dependencies]
cached = { workspace = true }
glob-match = "0.2.1"
mako_core = { path = "../core" }
miette = { version = "5.10.0", features = ["fancy"] }
oxc_resolver = "1.5.4"
serde = { workspace = true }
serde_json = { workspace = true }
swc_core = { workspace = true, features = ["swc_ecma_quote_macros"] }
url = { version = "2.5.0" }
cached = { workspace = true }
glob-match = "0.2.1"
mako_core = { path = "../core" }
miette = { version = "5.10.0", features = ["fancy"] }
oxc_resolver = "1.5.4"
percent-encoding = { version = "2.3.1" }
serde = { workspace = true }
serde_json = { workspace = true }
swc_core = { workspace = true, features = ["swc_ecma_quote_macros"] }
url = { version = "2.5.0" }

[target.'cfg(not(target_os = "linux"))'.dependencies]
mimalloc-rust = { workspace = true }
Expand Down
4 changes: 4 additions & 0 deletions crates/mako/src/ast_2/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use mako_core::regex::Regex;
use mako_core::thiserror::Error;
use mako_core::twox_hash::XxHash64;
use mako_core::{md5, mime_guess};
use percent_encoding::percent_decode_str;
use url::Url;

use crate::compiler::Context;
Expand Down Expand Up @@ -262,5 +263,8 @@ fn parse_path(path: &str) -> Result<(PathName, Search, Params, Fragment)> {
.query_pairs()
.map(|(k, v)| (k.to_string(), v.to_string()))
.collect();
// dir or filename may contains space or other special characters
// so we need to decode it, e.g. "a%20b" -> "a b"
let path = percent_decode_str(&path).decode_utf8()?;
Ok((path.to_string(), search, query_vec, fragment))
}
8 changes: 8 additions & 0 deletions e2e/fixtures/resolve.unescape-path/expect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const assert = require("assert");
const { parseBuildResult, trim, moduleReg } = require("../../../scripts/test-utils");
const { files } = parseBuildResult(__dirname);

const content = files["index.js"];

assert(content.includes(`console.log('中');`), "should contain 中");
assert(content.includes(`console.log('a b');`), "should contain a b");
3 changes: 3 additions & 0 deletions e2e/fixtures/resolve.unescape-path/mako.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"minify": false
}
1 change: 1 addition & 0 deletions e2e/fixtures/resolve.unescape-path/src/a b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('a b');
2 changes: 2 additions & 0 deletions e2e/fixtures/resolve.unescape-path/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './a b';
import './中';
1 change: 1 addition & 0 deletions e2e/fixtures/resolve.unescape-path/src/中.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('中');
3 changes: 2 additions & 1 deletion scripts/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import 'zx/globals';
(async () => {
const baseline = argv.baseline || 'master';
const multiChunks = argv.multiChunks;
const casePath = argv.case || multiChunks ? './tmp/three10x/multiChunks' : './tmp/three10x';
const casePath =
argv.case || multiChunks ? './tmp/three10x/multiChunks' : './tmp/three10x';

const currentBranch = (
await $`git rev-parse --abbrev-ref HEAD`
Expand Down

0 comments on commit 17259de

Please sign in to comment.