File tree Expand file tree Collapse file tree 2 files changed +7
-1
lines changed
Expand file tree Collapse file tree 2 files changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ const encodeURL = (str: string) => {
88 // Exit if input is a data url
99 if ( parsed . origin === 'null' ) return str ;
1010
11- parsed . search = encodeURI ( unescape ( parsed . search ) ) ;
11+ parsed . search = new URLSearchParams ( parsed . search ) . toString ( ) ;
1212 parsed . pathname = encodeURI ( decodeURI ( parsed . pathname ) ) ;
1313 // preserve IDN
1414 return format ( parsed , { unicode : true } ) ;
Original file line number Diff line number Diff line change @@ -63,6 +63,12 @@ describe('encodeURL', () => {
6363 encodeURL ( content ) . should . eql ( 'http://foo.com/bar?query=b%C3%A1z#f%C3%B3o' ) ;
6464 } ) ;
6565
66+ it ( 'perserve escape in search' , ( ) => {
67+ // https://github.com/hexojs/hexo-util/issues/411
68+ const content = 'https://fóo.com/path?search1=2%2B2&search2=bár' ;
69+ encodeURL ( content ) . should . eql ( content . replace ( 'bár' , 'b%C3%A1r' ) ) ;
70+ } ) ;
71+
6672 it ( 'idn' , ( ) => {
6773 const content = 'http://bár.com/baz' ;
6874 encodeURL ( content ) . should . eql ( 'http://bár.com/baz' ) ;
You can’t perform that action at this time.
0 commit comments