Skip to content

Commit a5b5d81

Browse files
fix pathToUri on windows (#32)
1 parent 1c1323f commit a5b5d81

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

utils.nim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,18 @@ proc pathToUri*(path: string): string =
101101
# the / character, meaning a full file path can be passed in without breaking
102102
# it.
103103
result = "file://" & newStringOfCap(path.len + path.len shr 2) # assume 12% non-alnum-chars
104+
when defined(windows):
105+
add(result, '/')
104106
for c in path:
105107
case c
106108
# https://tools.ietf.org/html/rfc3986#section-2.3
107109
of 'a'..'z', 'A'..'Z', '0'..'9', '-', '.', '_', '~', '/': add(result, c)
110+
of '\\':
111+
when defined(windows):
112+
add(result, '/')
113+
else:
114+
add(result, '%')
115+
add(result, toHex(ord(c), 2))
108116
else:
109117
add(result, '%')
110118
add(result, toHex(ord(c), 2))

0 commit comments

Comments
 (0)