Support headers with spaces in their value

This commit is contained in:
Quentin 2022-05-04 09:14:39 +02:00
parent 625fd24113
commit 6383d98772
Signed by: quentin
GPG Key ID: E9602264D639FF68
1 changed files with 17 additions and 1 deletions

View File

@ -161,7 +161,7 @@ fn parse_tricot_tag(
}
fn parse_tricot_add_header_tag(tag: &str) -> Option<(String, String)> {
let splits = tag.split(' ').collect::<Vec<_>>();
let splits = tag.splitn(3, ' ').collect::<Vec<_>>();
if splits.len() == 3 && splits[0] == "tricot-add-header" {
Some((splits[1].to_string(), splits[2].to_string()))
} else {
@ -352,3 +352,19 @@ pub fn spawn_proxy_config_task(
rx
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_parse_tricot_add_header_tag() {
match parse_tricot_add_header_tag("tricot-add-header Content-Security-Policy default-src 'none'; img-src 'self'; script-src 'self'; style-src 'self'") {
Some((name, value)) => {
assert_eq!(name, "Content-Security-Policy");
assert_eq!(value, "default-src 'none'; img-src 'self'; script-src 'self'; style-src 'self'");
}
_ => panic!("Passed a valid tag but the function says it is not valid")
}
}
}