fix: URL encoding issue (closes #2602) (#2601)

This commit is contained in:
Luxalpa 2024-06-02 20:06:41 +02:00 committed by GitHub
parent 21a6551ce6
commit 2ef27cb0bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 7 additions and 6 deletions

View file

@ -30,8 +30,6 @@ impl ParamsMap {
/// Inserts a value into the map.
#[inline(always)]
pub fn insert(&mut self, key: String, value: String) -> Option<String> {
use crate::history::url::unescape;
let value = unescape(&value);
self.0.insert(key, value)
}

View file

@ -25,7 +25,7 @@ pub fn unescape(s: &str) -> String {
#[cfg(not(feature = "ssr"))]
pub fn unescape(s: &str) -> String {
js_sys::decode_uri(s).unwrap().into()
js_sys::decode_uri_component(s).unwrap().into()
}
#[cfg(feature = "ssr")]
@ -36,7 +36,7 @@ pub fn escape(s: &str) -> String {
#[cfg(not(feature = "ssr"))]
pub fn escape(s: &str) -> String {
js_sys::encode_uri(s).as_string().unwrap()
js_sys::encode_uri_component(s).as_string().unwrap()
}
#[cfg(not(feature = "ssr"))]

View file

@ -1,7 +1,7 @@
// Implementation based on Solid Router
// see <https://github.com/solidjs/solid-router/blob/main/src/utils.ts>
use crate::ParamsMap;
use crate::{unescape, ParamsMap};
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc(hidden)]
@ -68,7 +68,10 @@ impl Matcher {
self.segments.iter().zip(loc_segments.iter())
{
if let Some(param_name) = segment.strip_prefix(':') {
params.insert(param_name.into(), (*loc_segment).into());
params.insert(
param_name.into(),
unescape(*loc_segment).into(),
);
} else if segment != loc_segment {
// if any segment doesn't match and isn't a param, there's no path match
return None;