@@ -10,6 +10,8 @@ const ABSOLUTE_BASES = [
1010 'http://h/p/q/'
1111]
1212
13+ const RELATIVE_BASES = [ '' , 'base' , 'relative/base' ]
14+
1315test ( 'normalize keeps the meaning of relative-path references' , ( t ) => {
1416 const cases = [
1517 [ 'a/../b' , 'b' ] ,
@@ -57,7 +59,7 @@ test('equal does not alias relative references with different targets', (t) => {
5759} )
5860
5961test ( 'resolving a normalized relative reference matches resolving the original' , ( t ) => {
60- for ( const base of ABSOLUTE_BASES ) {
62+ for ( const base of [ ... ABSOLUTE_BASES , ... RELATIVE_BASES ] ) {
6163 for ( const ref of [ 'a/../b' , 'x/..' , '../x' , './../x' , 'a/b/../../..' , '.' , '..' , './/x' ] ) {
6264 t . equal (
6365 fastURI . resolve ( base , fastURI . normalize ( ref ) ) ,
@@ -116,6 +118,18 @@ test('property: normalization of relative references is resolution-preserving an
116118 t . end ( )
117119} )
118120
121+ test ( 'suffix normalization preserves relative path meaning' , ( t ) => {
122+ const options = { reference : 'suffix' , scheme : 'x' }
123+ for ( const [ input , expected ] of [
124+ [ 'a/../b' , 'b' ] ,
125+ [ 'x/..' , './' ] ,
126+ [ 'a/../a:b' , './a:b' ]
127+ ] ) {
128+ t . equal ( fastURI . normalize ( input , options ) , expected , `${ input } -> ${ expected } ` )
129+ }
130+ t . end ( )
131+ } )
132+
119133test ( 'normalize does not promote a colon-first relative reference to a scheme (skipEscape)' , ( t ) => {
120134 // RFC 3986 section 4.2: a first path segment containing ":" must stay
121135 // protected by a leading "./", or it is mistaken for a scheme. Collapsing
0 commit comments