Skip to content

Commit 795a15c

Browse files
authored
fix: cancel HTML character escaping (#275)
1 parent f5d3a24 commit 795a15c

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
### Master
44

5+
- fix: cancel HTML character escaping
6+
57
### 3.0.39
68

79
- update: meta data

openapi/commando.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
package openapi
1515

1616
import (
17+
"bytes"
18+
1719
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses"
1820
"github.com/aliyun/aliyun-cli/cli"
1921
"github.com/aliyun/aliyun-cli/config"
@@ -175,11 +177,15 @@ func sortJSON(content string) string {
175177
if err != nil {
176178
return content
177179
}
178-
data, err := json.MarshalIndent(v, "", "\t")
180+
buf := new(bytes.Buffer)
181+
encoder := json.NewEncoder(buf)
182+
encoder.SetEscapeHTML(false)
183+
encoder.SetIndent("", "\t")
184+
err = encoder.Encode(v)
179185
if err != nil {
180186
return content
181187
}
182-
return string(data)
188+
return strings.TrimSuffix(buf.String(), "\n")
183189
}
184190

185191
// invoke with helper

openapi/commando_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ func Test_processInvoke(t *testing.T) {
208208
out := `{"requestid":"test","name":"json"}`
209209
out = sortJSON(out)
210210
assert.Equal(t, "{\n\t\"name\": \"json\",\n\t\"requestid\": \"test\"\n}", out)
211+
212+
out = `{"downloadlink":"aaa&bbb"}`
213+
out = sortJSON(out)
214+
assert.Equal(t, "{\n\t\"downloadlink\": \"aaa&bbb\"\n}", out)
211215
}
212216

213217
func Test_help(t *testing.T) {

0 commit comments

Comments
 (0)