File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change 2
2
3
3
## Unreleased - 2021-xx-xx
4
4
* When matching URL parameters, ` %25 ` is kept in the percent-encoded form - no longer decoded to ` % ` . [ #357 ]
5
+ * Fixed a bug where the ` Path ` extractor returns unsafe malformed string due to malformed URL. [ #359 ]
5
6
6
7
[ #357 ] : https://github.com/actix/actix-net/pull/357
8
+ [ #359 ] : https://github.com/actix/actix-net/pull/359
7
9
8
10
9
11
## 0.2.7 - 2021-02-06
Original file line number Diff line number Diff line change @@ -170,11 +170,7 @@ impl Quoter {
170
170
idx += 1 ;
171
171
}
172
172
173
- cloned. map ( |data| {
174
- // SAFETY: we get data from http::Uri, which does UTF-8 checks already
175
- // this code only decodes valid pct encoded values
176
- unsafe { String :: from_utf8_unchecked ( data) }
177
- } )
173
+ cloned. map ( |data| String :: from_utf8_lossy ( & data) . into_owned ( ) )
178
174
}
179
175
}
180
176
@@ -259,6 +255,16 @@ mod tests {
259
255
assert_eq ! ( path. get( "id" ) . unwrap( ) , & test) ;
260
256
}
261
257
258
+ #[ test]
259
+ fn test_invalid_utf8 ( ) {
260
+ let invalid_utf8 = percent_encode ( ( 0x80 ..=0xff ) . collect :: < Vec < _ > > ( ) . as_slice ( ) ) ;
261
+ let uri = Uri :: try_from ( format ! ( "/{}" , invalid_utf8) ) . unwrap ( ) ;
262
+ let path = Path :: new ( Url :: new ( uri) ) ;
263
+
264
+ // We should always get a valid utf8 string
265
+ assert ! ( String :: from_utf8( path. path( ) . as_bytes( ) . to_owned( ) ) . is_ok( ) ) ;
266
+ }
267
+
262
268
#[ test]
263
269
fn test_from_hex ( ) {
264
270
let hex = b"0123456789abcdefABCDEF" ;
You can’t perform that action at this time.
0 commit comments