File tree Expand file tree Collapse file tree 2 files changed +23
-8
lines changed Expand file tree Collapse file tree 2 files changed +23
-8
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ class << self
9
9
sig { params ( path : String , scheme : String ) . returns ( URI ::Generic ) }
10
10
def from_path ( path :, scheme : "file" )
11
11
# On Windows, if the path begins with the disk name, we need to add a leading slash to make it a valid URI
12
- escaped_path = if /^[A-Z]:/ . match? ( path )
12
+ escaped_path = if /^[A-Z]:/i . match? ( path )
13
13
DEFAULT_PARSER . escape ( "/#{ path } " )
14
14
else
15
15
DEFAULT_PARSER . escape ( path )
@@ -26,15 +26,15 @@ def to_standardized_path
26
26
parsed_path = path
27
27
return unless parsed_path
28
28
29
+ unescaped_path = CGI . unescape ( parsed_path )
30
+
29
31
# On Windows, when we're getting the file system path back from the URI, we need to remove the leading forward
30
32
# slash
31
- actual_path = if %r{^/[A-Z]:} . match? ( parsed_path )
32
- parsed_path . delete_prefix ( "/" )
33
+ if %r{^/[A-Z]:}i . match? ( unescaped_path )
34
+ unescaped_path . delete_prefix ( "/" )
33
35
else
34
- parsed_path
36
+ unescaped_path
35
37
end
36
-
37
- CGI . unescape ( actual_path )
38
38
end
39
39
40
40
sig { returns ( String ) }
Original file line number Diff line number Diff line change @@ -15,14 +15,29 @@ def test_from_path_on_windows
15
15
assert_equal ( "/C:/some/windows/path/to/file.rb" , uri . path )
16
16
end
17
17
18
- def test_to_path_on_unix
18
+ def test_from_path_on_windows_with_lowercase_drive
19
+ uri = URI ::Generic . from_path ( path : "c:/some/windows/path/to/file.rb" )
20
+ assert_equal ( "/c:/some/windows/path/to/file.rb" , uri . path )
21
+ end
22
+
23
+ def test_to_standardized_path_on_unix
19
24
uri = URI ::Generic . from_path ( path : "/some/unix/path/to/file.rb" )
20
25
assert_equal ( uri . path , uri . to_standardized_path )
21
26
end
22
27
23
- def test_to_path_on_windows
28
+ def test_to_standardized_path_on_windows
24
29
uri = URI ::Generic . from_path ( path : "C:/some/windows/path/to/file.rb" )
25
30
assert_equal ( "C:/some/windows/path/to/file.rb" , uri . to_standardized_path )
26
31
end
32
+
33
+ def test_to_standardized_path_on_windows_with_lowercase_drive
34
+ uri = URI ::Generic . from_path ( path : "c:/some/windows/path/to/file.rb" )
35
+ assert_equal ( "c:/some/windows/path/to/file.rb" , uri . to_standardized_path )
36
+ end
37
+
38
+ def test_to_standardized_path_on_windows_with_received_uri
39
+ uri = URI ( "file:///c%3A/some/windows/path/to/file.rb" )
40
+ assert_equal ( "c:/some/windows/path/to/file.rb" , uri . to_standardized_path )
41
+ end
27
42
end
28
43
end
You can’t perform that action at this time.
0 commit comments