@@ -25,11 +25,8 @@ const url = require('url');
2525 const forbiddenHostnameChars = [
2626 '\\\\exa mple\\share\\file.txt' ,
2727 '\\\\host name\\share\\file.txt' , // space
28- '\\\\host#name\\share\\file.txt' , // hash
29- '\\\\host?name\\share\\file.txt' , // question mark
3028 '\\\\host@name\\share\\file.txt' , // at sign
3129 '\\\\host:name\\share\\file.txt' , // colon
32- '\\\\host/name\\share\\file.txt' , // forward slash
3330 '\\\\host[name\\share\\file.txt' , // left bracket
3431 '\\\\host]name\\share\\file.txt' , // right bracket
3532 ] ;
@@ -42,6 +39,48 @@ const url = require('url');
4239 }
4340}
4441
42+ {
43+ const hostnameStateTerminatorTestCases = [
44+ {
45+ path : '\\\\host#name\\share\\file.txt' ,
46+ expected : 'file://host/share/file.txt' ,
47+ } ,
48+ {
49+ path : '\\\\host?name\\share\\file.txt' ,
50+ expected : 'file://host/share/file.txt' ,
51+ } ,
52+ {
53+ path : '\\\\host/name\\share\\file.txt' ,
54+ expected : 'file://host/share/file.txt' ,
55+ } ,
56+ ] ;
57+ for ( const { path, expected } of hostnameStateTerminatorTestCases ) {
58+ const actual = url . pathToFileURL ( path , { windows : true } ) . href ;
59+ assert . strictEqual ( actual , expected ) ;
60+ }
61+ }
62+
63+ {
64+ const ignoredHostnameCodePointTestCases = [
65+ {
66+ path : '\\\\host\nname\\share\\file.txt' ,
67+ expected : 'file://hostname/share/file.txt' ,
68+ } ,
69+ {
70+ path : '\\\\host\rname\\share\\file.txt' ,
71+ expected : 'file://hostname/share/file.txt' ,
72+ } ,
73+ {
74+ path : '\\\\host\tname\\share\\file.txt' ,
75+ expected : 'file://hostname/share/file.txt' ,
76+ } ,
77+ ] ;
78+ for ( const { path, expected } of ignoredHostnameCodePointTestCases ) {
79+ const actual = url . pathToFileURL ( path , { windows : true } ) . href ;
80+ assert . strictEqual ( actual , expected ) ;
81+ }
82+ }
83+
4584{
4685 if ( isWindows ) {
4786 // UNC path: \\server\share\resource
0 commit comments