Skip to content

Commit

Permalink
fix uri and urid formats not to convert a space between a plus sign
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny committed Aug 21, 2024
1 parent 7f0828d commit 24c60a5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions cli/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6285,9 +6285,9 @@
args:
- '@uri'
input: |
[1, {"foo": "<div>&'\"()</div>"}]
[1, {"foo": "<div>&'\"()+</div>"}]
expected: |
"%5B1%2C%7B%22foo%22%3A%22%3Cdiv%3E%26%27%5C%22%28%29%3C%2Fdiv%3E%22%7D%5D"
"%5B1%2C%7B%22foo%22%3A%22%3Cdiv%3E%26%27%5C%22%28%29%2B%3C%2Fdiv%3E%22%7D%5D"
- name: format strings @uri with string interpolation
args:
Expand All @@ -6301,9 +6301,9 @@
args:
- '@urid'
input: |
"%5B1%2C%7B%22foo%22%3A%22%3Cdiv%3E%26%27%5C%22%28%29%3C%2Fdiv%3E%22%7D%5D"
"%5B1%2C%7B%22foo%22%3A%22%3Cdiv%3E%26%27%5C%22%28%29%2B%3C%2Fdiv%3E%22%7D%5D"
expected: |
"[1,{\"foo\":\"<div>&'\\\"()</div>\"}]"
"[1,{\"foo\":\"<div>&'\\\"()+</div>\"}]"
- name: format strings @urid error
args:
Expand Down
4 changes: 2 additions & 2 deletions func.go
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ func funcToHTML(v any) any {
func funcToURI(v any) any {
switch x := funcToString(v).(type) {
case string:
return url.QueryEscape(x)
return strings.ReplaceAll(url.QueryEscape(x), "+", "%20")
default:
return x
}
Expand All @@ -893,7 +893,7 @@ func funcToURI(v any) any {
func funcToURId(v any) any {
switch x := funcToString(v).(type) {
case string:
x, err := url.QueryUnescape(x)
x, err := url.QueryUnescape(strings.ReplaceAll(x, "+", "%2B"))
if err != nil {
return &func0WrapError{"@urid", v, err}
}
Expand Down

0 comments on commit 24c60a5

Please sign in to comment.