Skip to content

Commit 8da6322

Browse files
committed
fix(obj-c + swift) handling boolean literal values
obj-c and swift used to not handle converting boolean values to their respective literal notation. Fix Kong#65
1 parent ab267a7 commit 8da6322

25 files changed

Lines changed: 35 additions & 25 deletions

File tree

src/targets/objc/helpers.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ module.exports = {
6161
keyValuePairs.push(util.format('@"%s": %s', k, this.literalRepresentation(value[k])))
6262
}
6363
return '@{ ' + keyValuePairs.join(join) + ' }'
64+
case '[object Boolean]':
65+
return value ? '@YES' : '@NO'
6466
default:
65-
return '@"' + value.replace(/"/g, '\\"') + '"'
67+
return '@"' + value.toString().replace(/"/g, '\\"') + '"'
6668
}
6769
}
6870
}

src/targets/swift/helpers.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ module.exports = {
7171
keyValuePairs.push(util.format('"%s": %s', k, this.literalRepresentation(value[k], opts, indentLevel)))
7272
}
7373
return concatArray(keyValuePairs, opts.pretty && keyValuePairs.length > 1, opts.indent, indentLevel)
74+
case '[object Boolean]':
75+
return value.toString()
7476
default:
75-
return '"' + value.replace(/"/g, '\\"') + '"'
77+
return '"' + value.toString().replace(/"/g, '\\"') + '"'
7678
}
7779
}
7880
}

test/fixtures/output/c/libcurl/application-json.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ struct curl_slist *headers = NULL;
77
headers = curl_slist_append(headers, "content-type: application/json");
88
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);
99

10-
curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}");
10+
curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}], \"boolean\": false}");
1111

1212
CURLcode ret = curl_easy_perform(hnd);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var client = new RestClient("http://mockbin.com/har");
22
var request = new RestRequest(Method.POST);
33
request.AddHeader("content-type", "application/json");
4-
request.AddParameter("application/json", "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}", ParameterType.RequestBody);
4+
request.AddParameter("application/json", "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}], \"boolean\": false}", ParameterType.RequestBody);
55
IRestResponse response = client.Execute(request);

test/fixtures/output/go/native/application-json.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func main() {
1111

1212
url := "http://mockbin.com/har"
1313

14-
payload := strings.NewReader("{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}")
14+
payload := strings.NewReader("{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}], \"boolean\": false}")
1515

1616
req, _ := http.NewRequest("POST", url, payload)
1717

test/fixtures/output/java/okhttp/application-json.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
OkHttpClient client = new OkHttpClient();
22

33
MediaType mediaType = MediaType.parse("application/json");
4-
RequestBody body = RequestBody.create(mediaType, "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}");
4+
RequestBody body = RequestBody.create(mediaType, "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}], \"boolean\": false}");
55
Request request = new Request.Builder()
66
.url("http://mockbin.com/har")
77
.post(body)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
HttpResponse<String> response = Unirest.post("http://mockbin.com/har")
22
.header("content-type", "application/json")
3-
.body("{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}")
3+
.body("{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}], \"boolean\": false}")
44
.asString();

test/fixtures/output/javascript/jquery/application-json.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var settings = {
77
"content-type": "application/json"
88
},
99
"processData": false,
10-
"data": "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}"
10+
"data": "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}], \"boolean\": false}"
1111
}
1212

1313
$.ajax(settings).done(function (response) {

test/fixtures/output/javascript/xhr/application-json.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ var data = JSON.stringify({
1515
{
1616
"arr_mix_nested": {}
1717
}
18-
]
18+
],
19+
"boolean": false
1920
});
2021

2122
var xhr = new XMLHttpRequest();

test/fixtures/output/node/native/application-json.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ req.write(JSON.stringify({ number: 1,
2727
string: 'f"oo',
2828
arr: [ 1, 2, 3 ],
2929
nested: { a: 'b' },
30-
arr_mix: [ 1, 'a', { arr_mix_nested: {} } ] }));
30+
arr_mix: [ 1, 'a', { arr_mix_nested: {} } ],
31+
boolean: false }));
3132
req.end();

0 commit comments

Comments
 (0)