Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nmattia committed Oct 24, 2023
1 parent 639703b commit 74a8bb4
Showing 1 changed file with 53 additions and 6 deletions.
59 changes: 53 additions & 6 deletions src/internet_identity/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ fn filepath_to_asset_paths(file_path: String) -> Vec<String> {
// TODO: check if &"..." == is ok
// TODO: filter out empty strings?
// TODO: split by "/" or Path sep?

let parts: Vec<&str> = file_path.split("/").collect();

match parts.split_last() {
Expand All @@ -317,17 +316,23 @@ fn filepath_to_asset_paths(file_path: String) -> Vec<String> {
if last == &"index.html" && elements.len() == 0 {
vec!["".to_string(), "index.html".to_string()]
} else if last == &"index.html" {
vec![elements.join("/").to_string()] // + <elements>/index.html
let prefix = elements.join("/").to_string();
vec![ format!("{prefix}"), format!("{prefix}/"), format!("{prefix}/index.html")]
} else if let Some(foo) = last.strip_suffix(".html") {
let mut elements = elements.to_vec();
elements.push(foo);
let prefix = elements.join("/").to_string();
vec![[prefix, foo.to_string()].join("/").to_string()] // + <elements>/<foo>.html
vec![ format!("{prefix}"), format!("{prefix}/"), format!("{prefix}/index.html")]
} else if let Some(foo) = last.strip_suffix(".gz") {
let prefix = elements.join("/").to_string();
let mut elements = elements.to_vec();
elements.push(foo);
// TODO: note about this being safe because we always reduce (.gz)
filepath_to_asset_paths([prefix, foo.to_string()].join("/").to_string())
filepath_to_asset_paths(elements.join("/").to_string())
} else {
let mut elements = elements.to_vec();
elements.push(last);
let prefix = elements.join("/").to_string();
vec![[prefix, last.to_string()].join("/").to_string()]
vec![prefix]
}
}
}
Expand All @@ -349,6 +354,15 @@ fn test_foo() {
vec!["".to_string(), "index.html".to_string()],
);

foo(
"foo.html".to_string(),
vec![
"foo".to_string(),
"foo/".to_string(),
"foo/index.html".to_string(),
],
);

foo(
"foo/index.html".to_string(),
vec![
Expand All @@ -357,4 +371,37 @@ fn test_foo() {
"foo/index.html".to_string(),
],
);

foo(
"foo.bar.gz".to_string(),
vec![
"foo.bar".to_string(),
],
);

foo(
"sub/foo.bar.gz".to_string(),
vec![
"sub/foo.bar".to_string(),
],
);

foo(
"foo.html.gz".to_string(),
vec![
"foo".to_string(),
"foo/".to_string(),
"foo/index.html".to_string(),
],
);

foo(
"sub/foo.html.gz".to_string(),
vec![
"sub/foo".to_string(),
"sub/foo/".to_string(),
"sub/foo/index.html".to_string(),
],
);

}

0 comments on commit 74a8bb4

Please sign in to comment.