fix: skip empty query keys

This commit is contained in:
Compositr 2024-11-04 22:24:42 +11:00
parent 8bc33130a9
commit 48eb9f8e3c

View file

@ -26,6 +26,12 @@ impl URL {
Some(key) => key.to_string(), Some(key) => key.to_string(),
None => continue, None => continue,
}; };
// Skip empty keys should they appear
if key.len() == 0 {
continue;
}
let value = key_value let value = key_value
.next() .next()
.unwrap_or("") .unwrap_or("")
@ -125,6 +131,7 @@ mod tests {
let url = URL::new("/path/to/resource".to_string()).unwrap(); let url = URL::new("/path/to/resource".to_string()).unwrap();
assert_eq!(url.path, "/path/to/resource"); assert_eq!(url.path, "/path/to/resource");
assert_eq!(url.query.len(), 0);
let url = URL::new("/path/to/resource?query=string".to_string()).unwrap(); let url = URL::new("/path/to/resource?query=string".to_string()).unwrap();
assert_eq!(url.path, "/path/to/resource"); assert_eq!(url.path, "/path/to/resource");