Skip to content

Commit 0218ec2

Browse files
committed
fix: fix boolean value
1 parent fce13f2 commit 0218ec2

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

src/main/resources/scripts/example/aiohttp.js

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* @author Mr.lin
3+
* @version 1.0.0
4+
*
5+
*/
6+
17
function escapeString(input) {
28
return `"${input.replaceAll("\"", "\\\\\"")}"`
39
}
@@ -6,8 +12,16 @@ function isEmpty(value) {
612
return !value || typeof value == 'object' && Object.keys(value).length === 0
713
}
814

9-
function decodeURIData(value) {
10-
return typeof value == "string" ? decodeURI(value) : value
15+
function jsonReplacer(key, value) {
16+
if (typeof value == "boolean"){
17+
return value ? "true" : "false"
18+
}
19+
else if (typeof value == "string"){
20+
return decodeURI(value)
21+
}
22+
else {
23+
return value
24+
}
1125
}
1226

1327
function transformForm(input) {
@@ -46,7 +60,7 @@ function transform(input) {
4660
}
4761

4862
if (!isEmpty(input.params)) {
49-
pyCode.push(`params = ${JSON.stringify(input.params, (k, v) => decodeURIData(v), 4)}`)
63+
pyCode.push(`params = ${JSON.stringify(input.params, jsonReplacer, 4)}`)
5064
params.push("params = params")
5165
}
5266

@@ -59,12 +73,12 @@ function transform(input) {
5973
let body = {}
6074
for (let item of input.data.split("&")) {
6175
let kv = item.split("=")
62-
body[kv[0]] = decodeURIData(kv[1])
76+
body[kv[0]] = jsonReplacer(undefined, kv[1])
6377
}
6478
pyCode.push(`data = ${JSON.stringify(body, null, 4)}`)
6579
params.push("data = data")
6680
} else if (input.headers["content-type"].indexOf("json") !== -1) {
67-
pyCode.push(`json = ${JSON.stringify(JSON.parse(input.data), (k, v) => decodeURIData(v), 4)}`)
81+
pyCode.push(`json = ${JSON.stringify(JSON.parse(input.data), jsonReplacer, 4)}`)
6882
params.push(`json = json`)
6983
} else {
7084
pyCode.push(`data = ${escapeString(input.data)}`)

src/main/resources/scripts/example/okhttp.js

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* @author Mr.lin
3+
* @version 1.0.0
4+
*
5+
*/
6+
17
function escapeString(input) {
28
return `"${input.replaceAll("\"", "\\\\\"")}"`
39
}

src/main/resources/scripts/example/requests.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* @author Mr.lin
3+
* @version 1.0.0
4+
*
5+
*/
6+
17
function escapeString(input) {
28
return `"${input.replaceAll("\"", "\\\\\"")}"`
39
}
@@ -6,8 +12,14 @@ function isEmpty(value) {
612
return !value || typeof value == 'object' && Object.keys(value).length === 0
713
}
814

9-
function decodeURIData(value) {
10-
return typeof value == "string" ? decodeURI(value) : value
15+
function jsonReplacer(key, value) {
16+
if (typeof value == "boolean") {
17+
return value ? "true" : "false"
18+
} else if (typeof value == "string") {
19+
return decodeURI(value)
20+
} else {
21+
return value
22+
}
1123
}
1224

1325
function transformForm(input) {
@@ -59,7 +71,7 @@ function transform(input) {
5971
}
6072

6173
if (!isEmpty(input.params)) {
62-
pyCode.push(`params = ${JSON.stringify(input.params, (k, v) => decodeURIData(v), 4)}`)
74+
pyCode.push(`params = ${JSON.stringify(input.params, jsonReplacer, 4)}`)
6375
params.push("params = params")
6476
}
6577

@@ -69,12 +81,12 @@ function transform(input) {
6981
let body = {}
7082
for (let item of input.data.split("&")) {
7183
let kv = item.split("=")
72-
body[kv[0]] = decodeURIData(kv[1])
84+
body[kv[0]] = jsonReplacer(undefined, kv[1])
7385
}
7486
pyCode.push(`data = ${JSON.stringify(body, null, 4)}`)
7587
params.push("data = data")
7688
} else if (input.headers["content-type"].indexOf("json") !== -1) {
77-
pyCode.push(`json = ${JSON.stringify(JSON.parse(input.data), (k, v) => decodeURIData(v), 4)}`)
89+
pyCode.push(`json = ${JSON.stringify(JSON.parse(input.data), jsonReplacer, 4)}`)
7890
params.push(`json = json`)
7991
} else {
8092
pyCode.push(`data = ${escapeString(input.data)}`)

0 commit comments

Comments
 (0)