Skip to content

Commit 851c8e1

Browse files
committed
fix(tpl/util/formatFileUrl): % should be escaped
Related issue: #4
1 parent 9a9d8a6 commit 851c8e1

File tree

5 files changed

+15
-0
lines changed

5 files changed

+15
-0
lines changed

src/tpl/util/formatFileUrl.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
)
66

77
var fileUrlReplacer = strings.NewReplacer(
8+
"%", "%25",
89
"?", "%3f",
910
"&", "%26",
1011
"#", "%23",

test/case/001.basic.bash

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,15 @@ assert "$file1" 'vhost1/file1.txt'
1414
(curl_get_body http://127.0.0.1:3003/hello/ | grep -q './index.txt') ||
1515
fail "resource /hello/ does not contains './index.txt'"
1616

17+
(curl_get_body 'http://127.0.0.1:3003/' | grep -q -F 'escape-escaped%252fslash') ||
18+
fail "link URL escape incorrect"
19+
(curl_get_body 'http://127.0.0.1:3003/' | grep -q -F 'escape%23sharp') ||
20+
fail "link URL escape incorrect"
21+
(curl_get_body 'http://127.0.0.1:3003/' | grep -q -F 'escape%25percent') ||
22+
fail "link URL escape incorrect"
23+
24+
assert $(curl_head_status 'http://127.0.0.1:3003/escape-escaped%252fslash/') '200'
25+
assert $(curl_head_status 'http://127.0.0.1:3003/escape%23sharp') '200'
26+
assert $(curl_head_status 'http://127.0.0.1:3003/escape%25percent') '200'
27+
1728
jobs -p | xargs kill

test/fs/vhost1/escape#sharp/index.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vhost1/escape#sharp/index.txt
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vhost1/escape%percent/index.txt
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vhost1/escape%2fslash/index.txt

0 commit comments

Comments
 (0)