This commit is contained in:
Mateusz Gruszczyński committed 2026-11-26 11:02:46 +01:00
1 parent aa0a271a1c
commit f38a2b9e5e
38 files changed
+1098 -160

No files matched your search

+7 -3
View File
@@ -428,8 +428,10 @@ impl CompiledRoute {
let tail = path.strip_prefix(&self.path_prefix).unwrap_or("");
if tail.is_empty() {
"/".to_owned()
} else {
} else if tail.starts_with('/') {
tail.to_owned()
} else {
format!("/{tail}")
}
}
RewriteMode::ReplacePrefix => {
@@ -442,9 +444,11 @@ impl CompiledRoute {
base.to_owned()
}
} else if base.is_empty() || base == "/" {
tail.to_owned()
} else {
if tail.starts_with('/') { tail.to_owned() } else { format!("/{tail}") }
} else if tail.starts_with('/') {
format!("{base}{tail}")
} else {
format!("{base}/{tail}")
}
}
RewriteMode::Regex => self
+26
View File
@@ -837,6 +837,32 @@ mod tests {
Some("/service/42/Ubuntu 14.04 LTS")
);
}
#[test]
fn web_service_prefix_mount_rewrite_keeps_absolute_script_paths() {
for prefix in ["/console", "/console/"] {
let mut config = demo_config("127.0.0.1:9000".parse().unwrap());
let route = &mut config.vhosts[0].routes[0];
route.id = "mount".into();
route.match_type = crate::vhost::PathMatch::Prefix;
route.path_prefix = prefix.into();
route.rewrite = crate::vhost::PathRewrite {
mode: crate::vhost::RewriteMode::StripPrefix,
value: String::new(),
};
let snapshot = compile(config.clone(), 1, &policy()).unwrap();
let selected = snapshot.select("localhost", "/console/status.php").unwrap();
assert_eq!(selected.rewritten_path("/console/status.php").unwrap().as_deref(), Some("/status.php"));
assert_eq!(selected.rewritten_path("/console/").unwrap().as_deref(), Some("/"));
config.vhosts[0].routes[0].rewrite = crate::vhost::PathRewrite {
mode: crate::vhost::RewriteMode::ReplacePrefix,
value: "/internal".into(),
};
let snapshot = compile(config, 1, &policy()).unwrap();
assert_eq!(snapshot.select("localhost", "/console/status.php").unwrap()
.rewritten_path("/console/status.php").unwrap().as_deref(), Some("/internal/status.php"));
}
}
#[test]
fn custom_location_response_is_validated() {
let mut c = demo_config("127.0.0.1:9000".parse().unwrap());