Skip to content

Commit 9d4c2af

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

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

crates/oxide/src/extractor/pre_processors/ruby.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::cursor;
44
use crate::extractor::bracket_stack;
55
use crate::extractor::pre_processors::pre_processor::PreProcessor;
6-
use crate::pre_process_input;
6+
use crate::scanner::pre_process_input;
77
use bstr::ByteSlice;
88
use fancy_regex::Regex;
99
use std::sync;

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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,4 +1585,30 @@ 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+
("src/🤦‍♂️/foo.tsx", "content-['src/🤦‍♂️/foo.tsx']"),
1601+
],
1602+
vec!["@source '**/*'", "@source not 'src/🤦‍♂️'"],
1603+
);
1604+
1605+
assert_eq!(
1606+
candidates,
1607+
vec!["content-['src/💩.js']", "content-['src/🤦‍♂️.tsx']"]
1608+
);
1609+
1610+
assert_eq!(files, vec!["src/💩.js", "src/🤦‍♂️.tsx"]);
1611+
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}"]);
1612+
assert_eq!(normalized_sources, vec!["**/*"]);
1613+
}
15881614
}

0 commit comments

Comments
 (0)