@@ -5,27 +5,42 @@ import { path2uri, symbolDescriptorMatch, uri2path } from '../util';
5
5
describe ( 'util' , ( ) => {
6
6
describe ( 'path2uri()' , ( ) => {
7
7
it ( 'should convert a Unix file path to a URI' , ( ) => {
8
- const uri = path2uri ( new URL ( 'file://host /foo/bar' ) , '/baz/@ qux' ) ;
9
- assert . equal ( uri . href , 'file://host /baz/%40qux ' ) ;
8
+ const uri = path2uri ( new URL ( 'file:///foo/bar' ) , '/baz/qux' ) ;
9
+ assert . equal ( uri . href , 'file:///baz/qux ' ) ;
10
10
} ) ;
11
11
it ( 'should convert a Windows file path to a URI' , ( ) => {
12
- // Host is dropped because of https://github.com/jsdom/whatwg-url/issues/84
13
- const uri = path2uri ( new URL ( 'file:///foo/bar' ) , 'C:\\baz\\@qux' ) ;
14
- assert . equal ( uri . href , 'file:///C:/baz/%40qux' ) ;
12
+ const uri = path2uri ( new URL ( 'file:///foo/bar' ) , 'C:\\baz\\qux' ) ;
13
+ assert . equal ( uri . href , 'file:///C:/baz/qux' ) ;
14
+ } ) ;
15
+ it ( 'should encode special characters' , ( ) => {
16
+ const uri = path2uri ( new URL ( 'file:///foo/bar' ) , '/💩' ) ;
17
+ assert . equal ( uri . href , 'file:///%F0%9F%92%A9' ) ;
18
+ } ) ;
19
+ it ( 'should encode unreserved special characters' , ( ) => {
20
+ const uri = path2uri ( new URL ( 'file:///foo/bar' ) , '/@baz' ) ;
21
+ assert . equal ( uri . href , 'file:///%40baz' ) ;
15
22
} ) ;
16
23
} ) ;
17
24
describe ( 'uri2path()' , ( ) => {
18
25
it ( 'should convert a Unix file URI to a file path' , ( ) => {
19
- const filePath = uri2path ( new URL ( 'file:///baz/%40qux ' ) ) ;
20
- assert . equal ( filePath , '/baz/@ qux' ) ;
26
+ const filePath = uri2path ( new URL ( 'file:///baz/qux ' ) ) ;
27
+ assert . equal ( filePath , '/baz/qux' ) ;
21
28
} ) ;
22
29
it ( 'should convert a Windows file URI to a file path' , ( ) => {
23
- const filePath = uri2path ( new URL ( 'file:///c:/baz/%40qux ' ) ) ;
24
- assert . equal ( filePath , 'c:\\baz\\@ qux' ) ;
30
+ const filePath = uri2path ( new URL ( 'file:///c:/baz/qux ' ) ) ;
31
+ assert . equal ( filePath , 'c:\\baz\\qux' ) ;
25
32
} ) ;
26
33
it ( 'should convert a Windows file URI with uppercase drive letter to a file path' , ( ) => {
27
- const filePath = uri2path ( new URL ( 'file:///C:/baz/%40qux' ) ) ;
28
- assert . equal ( filePath , 'C:\\baz\\@qux' ) ;
34
+ const filePath = uri2path ( new URL ( 'file:///C:/baz/qux' ) ) ;
35
+ assert . equal ( filePath , 'C:\\baz\\qux' ) ;
36
+ } ) ;
37
+ it ( 'should decode special characters' , ( ) => {
38
+ const filePath = uri2path ( new URL ( 'file:///%F0%9F%92%A9' ) ) ;
39
+ assert . equal ( filePath , '/💩' ) ;
40
+ } ) ;
41
+ it ( 'should decode unreserved special characters' , ( ) => {
42
+ const filePath = uri2path ( new URL ( 'file:///%40foo' ) ) ;
43
+ assert . equal ( filePath , '/@foo' ) ;
29
44
} ) ;
30
45
} ) ;
31
46
describe ( 'symbolDescriptorMatch' , ( ) => {
0 commit comments