Skip to content

Commit 5e9cdf8

Browse files
Cleanups and test utf8 special characters in paths
1 parent 5e7d035 commit 5e9cdf8

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

crates/oxide/src/scanner/sources.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,18 @@ impl PublicSourceEntry {
147147

148148
let base: PathBuf = self.base.clone().into();
149149
let base = match static_part {
150-
Some(static_part) => base.join(static_part),
151-
None => base,
152-
};
153-
154-
// TODO: If the base does not exist on disk, try removing the last slash and try again.
155-
let base = match dunce::canonicalize(&base) {
156-
Ok(base) => base,
157-
Err(err) => {
158-
event!(tracing::Level::ERROR, "Failed to resolve glob: {:?}", err);
159-
return;
150+
Some(static_part) => {
151+
// TODO: If the base does not exist on disk, try removing the last slash and try
152+
// again.
153+
match dunce::canonicalize(base.join(static_part)) {
154+
Ok(base) => base,
155+
Err(err) => {
156+
event!(tracing::Level::ERROR, "Failed to resolve glob: {:?}", err);
157+
return;
158+
}
159+
}
160160
}
161+
None => base,
161162
};
162163

163164
let pattern = match dynamic_part {

crates/oxide/tests/scanner.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,4 +1585,29 @@ mod scanner {
15851585

15861586
assert!(candidates.is_empty());
15871587
}
1588+
1589+
#[test]
1590+
fn test_works_with_utf8_special_character_paths() {
1591+
let ScanResult {
1592+
candidates,
1593+
files,
1594+
globs,
1595+
normalized_sources,
1596+
} = scan_with_globs(
1597+
&[
1598+
("src/💩.js", "content-['src/💩.js']"),
1599+
("src/🤦‍♂️.tsx", "content-['src/🤦‍♂️.tsx']"),
1600+
],
1601+
vec!["@source '**/*'"],
1602+
);
1603+
1604+
assert_eq!(
1605+
candidates,
1606+
vec!["content-['src/💩.js']", "content-['src/🤦‍♂️.tsx']"]
1607+
);
1608+
1609+
assert_eq!(files, vec!["src/💩.js", "src/🤦‍♂️.tsx"]);
1610+
assert_eq!(globs, vec!["*", "src/**/*.{aspx,astro,cjs,cts,eex,erb,gjs,gts,haml,handlebars,hbs,heex,html,jade,js,jsx,liquid,md,mdx,mjs,mts,mustache,njk,nunjucks,php,pug,py,razor,rb,rhtml,rs,slim,svelte,tpl,ts,tsx,twig,vue}"]);
1611+
assert_eq!(normalized_sources, vec!["**/*"]);
1612+
}
15881613
}

0 commit comments

Comments
 (0)