@@ -257,40 +257,23 @@ function fromFile (res, where) {
257257 } )
258258 }
259259
260- // environment switch for testing
261- if ( process . env . NPM_PACKAGE_ARG_8909_STRICT !== '1' ) {
262- // XXX backwards compatibility lack of compliance with 8909
263- // Remove when we want a breaking change to come into RFC compliance.
264- if ( resolvedUrl . host && resolvedUrl . host !== 'localhost' ) {
265- const rawSpec = res . rawSpec . replace ( / ^ f i l e : \/ \/ / , 'file:///' )
266- resolvedUrl = new url . URL ( rawSpec , `file://${ path . resolve ( where ) } /` )
267- specUrl = new url . URL ( rawSpec )
268- rawNoPrefix = rawSpec . replace ( / ^ f i l e : / , '' )
269- }
270- // turn file:/../foo into file:../foo
271- // for 1, 2 or 3 leading slashes since we attempted
272- // in the previous step to make it a file protocol url with a leading slash
273- if ( / ^ \/ { 1 , 3 } \. \. ? ( \/ | $ ) / . test ( rawNoPrefix ) ) {
274- const rawSpec = res . rawSpec . replace ( / ^ f i l e : \/ { 1 , 3 } / , 'file:' )
275- resolvedUrl = new url . URL ( rawSpec , `file://${ path . resolve ( where ) } /` )
276- specUrl = new url . URL ( rawSpec )
277- rawNoPrefix = rawSpec . replace ( / ^ f i l e : / , '' )
278- }
279- // XXX end 8909 violation backwards compatibility section
280- }
281-
282- // file:foo - relative url to ./foo
283- // file:/foo - absolute path /foo
284- // file:///foo - absolute path to /foo, no authority host
285- // file://localhost/foo - absolute path to /foo, on localhost
286- // file://foo - absolute path to / on foo host (error!)
260+ // XXX backwards compatibility lack of compliance with RFC 8909
287261 if ( resolvedUrl . host && resolvedUrl . host !== 'localhost' ) {
288- const msg = `Invalid file: URL, must be absolute if // present`
289- throw Object . assign ( new Error ( msg ) , {
290- raw : res . rawSpec ,
291- parsed : resolvedUrl ,
292- } )
262+ const rawSpec = res . rawSpec . replace ( / ^ f i l e : \/ \/ / , 'file:///' )
263+ resolvedUrl = new url . URL ( rawSpec , `file://${ path . resolve ( where ) } /` )
264+ specUrl = new url . URL ( rawSpec )
265+ rawNoPrefix = rawSpec . replace ( / ^ f i l e : / , '' )
266+ }
267+ // turn file:/../foo into file:../foo
268+ // for 1, 2 or 3 leading slashes since we attempted
269+ // in the previous step to make it a file protocol url with a leading slash
270+ if ( / ^ \/ { 1 , 3 } \. \. ? ( \/ | $ ) / . test ( rawNoPrefix ) ) {
271+ const rawSpec = res . rawSpec . replace ( / ^ f i l e : \/ { 1 , 3 } / , 'file:' )
272+ resolvedUrl = new url . URL ( rawSpec , `file://${ path . resolve ( where ) } /` )
273+ specUrl = new url . URL ( rawSpec )
274+ rawNoPrefix = rawSpec . replace ( / ^ f i l e : / , '' )
293275 }
276+ // XXX end RFC 8909 violation backwards compatibility section
294277
295278 // turn /C:/blah into just C:/blah on windows
296279 let specPath = decodeURIComponent ( specUrl . pathname )
0 commit comments