Skip to content

Commit f1db545

Browse files
committed
ensure glob entry without pattern is scanner correctly
1 parent 2e3d032 commit f1db545

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

crates/oxide/src/glob.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ pub fn hoist_static_glob_parts(entries: &Vec<GlobEntry>) -> Vec<GlobEntry> {
4747

4848
let pattern = match dynamic_part {
4949
Some(dynamic_part) => dynamic_part,
50-
None => "**/*".to_owned(),
50+
None => {
51+
if base.is_dir() {
52+
"**/*".to_owned()
53+
} else {
54+
"".to_owned()
55+
}
56+
}
5157
};
5258

5359
result.push(GlobEntry {

crates/oxide/src/lib.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,17 +271,27 @@ impl Scanner {
271271
// Turn `Vec<&GlobEntry>` in `Vec<GlobEntry>`
272272
let glob_sources: Vec<_> = glob_sources.into_iter().cloned().collect();
273273
let hoisted = hoist_static_glob_parts(&glob_sources);
274+
dbg!(&glob_sources, &hoisted);
274275

275276
for source in &hoisted {
276-
// We need to combine the base and the pattern, otherwise a pattern that looks like
277-
// `*.html`, will never match a path that looks like
277+
// If the pattern is empty, then the base points to a specific file or folder already
278+
// if it doesn't contain any dynamic parts. In that case we can use the base as the
279+
// pattern.
280+
//
281+
// Otherwise we need to combine the base and the pattern, otherwise a pattern that
282+
// looks like `*.html`, will never match a path that looks like
278283
// `/my-project/project-a/index.html`, because it contains `/`.
279284
//
280285
// We can't prepend `**/`, because then `/my-project/project-a/nested/index.html` would
281286
// match as well.
282287
//
283288
// Instead we combine the base and the pattern as a single glob pattern.
284-
let Ok(glob) = Glob::new(&format!("{}/{}", source.base, source.pattern)) else {
289+
let mut full_pattern = source.base.clone();
290+
if !source.pattern.is_empty() {
291+
full_pattern.push('/');
292+
full_pattern.push_str(&source.pattern);
293+
}
294+
let Ok(glob) = Glob::new(&full_pattern) else {
285295
continue;
286296
};
287297

0 commit comments

Comments
 (0)