Skip to content

Commit 7bbffb2

Browse files
committed
fix relative path error
1 parent 91127d7 commit 7bbffb2

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

tw5server.nim

+9-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ from parseBody import parseMPFD
1919

2020
const
2121
name = "TW5 server"
22-
version = "1.2.2"
22+
version = "1.2.3"
2323
style = staticRead("style.css")
2424
temp = staticRead("template.html")
2525
js = staticRead("main.js")
@@ -65,10 +65,15 @@ proc h_page(settings:NimHttpSettings, content, title, subtitle: string): string
6565

6666
proc relativePath(path, cwd: string): string =
6767
var path2 = path
68-
if cwd == "/":
69-
return path
68+
var wd = cwd
69+
if wd.endsWith("/"):
70+
wd.removeSuffix("/")
71+
if wd == "/":
72+
return wd
73+
elif wd == path2:
74+
return "/"
7075
else:
71-
path2.delete(0..cwd.len-1)
76+
path2.removePrefix(wd)
7277
var relpath = path2.replace("\\", "/")
7378
if (not relpath.endsWith("/")) and (not path.fileExists):
7479
relpath = relpath&"/"

0 commit comments

Comments
 (0)