Skip to content

Commit

Permalink
Use SPECIAL_PATH_SEGMENT when encoding path in from_file_path (#902)
Browse files Browse the repository at this point in the history
* Use SPECIAL_PATH_SEGMENT when encoding path in from_file_path

Fixes #901

* cargo fmt
  • Loading branch information
valenting committed Feb 2, 2024
1 parent f447500 commit b77a81b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions url/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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;
Expand Down Expand Up @@ -2817,7 +2819,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 {
Expand Down
1 change: 1 addition & 0 deletions url/tests/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down

0 comments on commit b77a81b

Please sign in to comment.