Skip to content

Commit

Permalink
fix: URL encoding issue (closes #2602) (#2601)
Browse files Browse the repository at this point in the history
  • Loading branch information
luxalpa authored Jun 2, 2024
1 parent 21a6551 commit 2ef27cb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 0 additions & 2 deletions router/src/history/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions router/src/history/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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"))]
Expand Down
7 changes: 5 additions & 2 deletions router/src/matching/matcher.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 2ef27cb

Please sign in to comment.