From f960421ddb8ccc11e452e119182c94db6ea35d59 Mon Sep 17 00:00:00 2001 From: Daniel Skarbek Date: Sun, 2 Apr 2017 15:11:26 -0700 Subject: [PATCH] Escape single quotes in json When the json ends up as a payload in a curl command, the single quotes will mess things up --- src/WebHelpers.bas | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/WebHelpers.bas b/src/WebHelpers.bas index 67eb997b..1ae33280 100644 --- a/src/WebHelpers.bas +++ b/src/WebHelpers.bas @@ -2539,11 +2539,15 @@ Private Function json_Encode(ByVal json_Text As Variant) As String End If ' From spec, ", \, and control characters must be escaped (solidus is optional) - + ' To avoid problems with quoting the payload on the command line in single quotes, need to escape ' also + Select Case json_AscCode Case 34 ' " -> 34 -> \" json_Char = "\""" + Case 39 + ' ' -> 39 -> \u0027 (decimal 39 is 27 in hex) + json_Char = "\u0027" Case 92 ' \ -> 92 -> \\ json_Char = "\\"