From 096ee1527f18d3978cf10c7cdd81fa2af97c7d17 Mon Sep 17 00:00:00 2001 From: Nathan C Date: Wed, 19 Aug 2020 22:03:06 -0400 Subject: [PATCH] fix: http handler not handling unicode gracefully --- sonorancad/core/http.js | 6 ++++-- sonorancad/core/server.lua | 4 ++-- sonorancad/plugins/apicheck | 2 +- sonorancad/plugins/livemap | 2 +- sonorancad/plugins/lookups | 2 +- sonorancad/plugins/pushevents | 2 +- sonorancad/plugins/wraithv2 | 2 +- 7 files changed, 11 insertions(+), 9 deletions(-) diff --git a/sonorancad/core/http.js b/sonorancad/core/http.js index 11d5d7b..dcdb742 100644 --- a/sonorancad/core/http.js +++ b/sonorancad/core/http.js @@ -1,5 +1,7 @@ +function byteCount(s) { + return encodeURI(s).split(/%..|./).length - 1; +} -//url, cb, method, data, headers exports('HandleHttpRequest', (dest, callback, method, data, headers) => { const urlObj = url.parse(dest) const options = { @@ -10,7 +12,7 @@ exports('HandleHttpRequest', (dest, callback, method, data, headers) => { } if (method == "POST") { options.headers['Content-Type'] = 'application/json', - options.headers['Content-Length'] = data.length + options.headers['Content-Length'] = byteCount(data) } else if (method != "GET") { console.error("Invalid request. Only GET/POST supported. Method: " + method); diff --git a/sonorancad/core/server.lua b/sonorancad/core/server.lua index cea0868..c22eb11 100644 --- a/sonorancad/core/server.lua +++ b/sonorancad/core/server.lua @@ -79,9 +79,9 @@ function performApiRequest(postData, type, cb) apiUrl = "https://api.sonoransoftware.com/" end PerformHttpRequest(apiUrl..tostring(endpoint), function(statusCode, res, headers) - debugPrint(("type %s called with post data %s to url %s"):format(type, json.encode(payload), Config.apiUrl..tostring(endpoint))) + --debugPrint(("type %s called with post data %s to url %s"):format(type, json.encode(payload), Config.apiUrl..tostring(endpoint))) if statusCode == 200 and res ~= nil then - debugPrint("result: "..tostring(res)) + --debugPrint("result: "..tostring(res)) cb(res, true) elseif statusCode == 404 then -- handle 404 requests, like from CHECK_APIID cb(res, false) diff --git a/sonorancad/plugins/apicheck b/sonorancad/plugins/apicheck index 4ec7d8a..bfecbb1 160000 --- a/sonorancad/plugins/apicheck +++ b/sonorancad/plugins/apicheck @@ -1 +1 @@ -Subproject commit 4ec7d8a6929547ec357cbfdd8e4f7e24c79b6851 +Subproject commit bfecbb1da3fa31f8d755797fa62132851ebb08dd diff --git a/sonorancad/plugins/livemap b/sonorancad/plugins/livemap index f3c23d0..3174aa8 160000 --- a/sonorancad/plugins/livemap +++ b/sonorancad/plugins/livemap @@ -1 +1 @@ -Subproject commit f3c23d0f0773bef7afeeb5dd2ff06608f02d5225 +Subproject commit 3174aa8329f4658683333b82f185a8dd15715799 diff --git a/sonorancad/plugins/lookups b/sonorancad/plugins/lookups index e0d8caa..4fd5c32 160000 --- a/sonorancad/plugins/lookups +++ b/sonorancad/plugins/lookups @@ -1 +1 @@ -Subproject commit e0d8caacaf5b74e0c295640de1540f41586c8cea +Subproject commit 4fd5c327fd2ac2c7c57cef943e436d0e8a20b877 diff --git a/sonorancad/plugins/pushevents b/sonorancad/plugins/pushevents index 1c08795..b1bccd0 160000 --- a/sonorancad/plugins/pushevents +++ b/sonorancad/plugins/pushevents @@ -1 +1 @@ -Subproject commit 1c08795525f49c94f74a9eb05e772c67535e0ed2 +Subproject commit b1bccd0eda7ace3397e3a10837c7e4d7400cc6e9 diff --git a/sonorancad/plugins/wraithv2 b/sonorancad/plugins/wraithv2 index 2531f41..c2a14b7 160000 --- a/sonorancad/plugins/wraithv2 +++ b/sonorancad/plugins/wraithv2 @@ -1 +1 @@ -Subproject commit 2531f411494b526f1a958a798ac177b843ce0f28 +Subproject commit c2a14b7a3023022d8cbbca04512f5e3684aee1bf