From f50733861c2549d21857070290a2863321a762b3 Mon Sep 17 00:00:00 2001 From: Valentin Gosu Date: Fri, 2 Feb 2024 16:42:22 +0100 Subject: [PATCH 1/2] Use SPECIAL_PATH_SEGMENT when encoding path in from_file_path Fixes #901 --- url/src/lib.rs | 4 ++-- url/tests/unit.rs | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/url/src/lib.rs b/url/src/lib.rs index d498ee365..454e11325 100644 --- a/url/src/lib.rs +++ b/url/src/lib.rs @@ -146,7 +146,7 @@ pub use form_urlencoded; extern crate serde; use crate::host::HostInternal; -use crate::parser::{to_u32, Context, Parser, SchemeType, PATH_SEGMENT, USERINFO}; +use crate::parser::{to_u32, Context, Parser, SchemeType, PATH_SEGMENT, SPECIAL_PATH_SEGMENT, USERINFO}; use percent_encoding::{percent_decode, percent_encode, utf8_percent_encode}; use std::borrow::Borrow; use std::cmp; @@ -2817,7 +2817,7 @@ fn path_to_file_url_segments( serialization.push('/'); serialization.extend(percent_encode( component.as_os_str().as_bytes(), - PATH_SEGMENT, + SPECIAL_PATH_SEGMENT, )); } if empty { diff --git a/url/tests/unit.rs b/url/tests/unit.rs index c27f237ba..f8069dc89 100644 --- a/url/tests/unit.rs +++ b/url/tests/unit.rs @@ -146,6 +146,7 @@ fn new_file_paths() { assert_from_file_path!("/foo/bar"); assert_from_file_path!("/foo/ba\0r", "/foo/ba%00r"); assert_from_file_path!("/foo/ba%00r", "/foo/ba%2500r"); + assert_from_file_path!("/foo/ba\\r", "/foo/ba%5Cr"); } } From 1ce0c83ce87a93ead9199347853cb6b4dd04cd99 Mon Sep 17 00:00:00 2001 From: Valentin Gosu Date: Fri, 2 Feb 2024 16:51:12 +0100 Subject: [PATCH 2/2] cargo fmt --- url/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/url/src/lib.rs b/url/src/lib.rs index 454e11325..78980e85f 100644 --- a/url/src/lib.rs +++ b/url/src/lib.rs @@ -146,7 +146,9 @@ pub use form_urlencoded; extern crate serde; use crate::host::HostInternal; -use crate::parser::{to_u32, Context, Parser, SchemeType, PATH_SEGMENT, SPECIAL_PATH_SEGMENT, USERINFO}; +use crate::parser::{ + to_u32, Context, Parser, SchemeType, PATH_SEGMENT, SPECIAL_PATH_SEGMENT, USERINFO, +}; use percent_encoding::{percent_decode, percent_encode, utf8_percent_encode}; use std::borrow::Borrow; use std::cmp;