aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--qobject/json-parser.c12
-rw-r--r--tests/check-qjson.c17
2 files changed, 17 insertions, 12 deletions
diff --git a/qobject/json-parser.c b/qobject/json-parser.c
index 273f448a52..63e9229f1c 100644
--- a/qobject/json-parser.c
+++ b/qobject/json-parser.c
@@ -144,7 +144,8 @@ static QString *parse_string(JSONParserContext *ctxt, JSONToken *token)
while (*ptr != quote) {
assert(*ptr);
- if (*ptr == '\\') {
+ switch (*ptr) {
+ case '\\':
beg = ptr++;
switch (*ptr++) {
case '"':
@@ -205,7 +206,14 @@ static QString *parse_string(JSONParserContext *ctxt, JSONToken *token)
parse_error(ctxt, token, "invalid escape sequence in string");
goto out;
}
- } else {
+ break;
+ case '%':
+ if (ctxt->ap) {
+ parse_error(ctxt, token, "can't interpolate into string");
+ goto out;
+ }
+ /* fall through */
+ default:
cp = mod_utf8_codepoint(ptr, 6, &end);
if (cp < 0) {
parse_error(ctxt, token, "invalid UTF-8 sequence in string");
diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index 936258ddd4..a1854573de 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -1037,16 +1037,13 @@ static void interpolation_unknown(void)
static void interpolation_string(void)
{
- QLitObject decoded = QLIT_QLIST(((QLitObject[]){
- QLIT_QSTR("%s"),
- QLIT_QSTR("eins"),
- {}}));
- QObject *qobj;
-
- /* Dangerous misfeature: % is silently ignored in strings */
- qobj = qobject_from_jsonf_nofail("['%s', %s]", "eins", "zwei");
- g_assert(qlit_equal_qobject(&decoded, qobj));
- qobject_unref(qobj);
+ if (g_test_subprocess()) {
+ qobject_from_jsonf_nofail("['%s', %s]", "eins", "zwei");
+ }
+ g_test_trap_subprocess(NULL, 0, 0);
+ g_test_trap_assert_failed();
+ g_test_trap_assert_stderr("*Unexpected error*"
+ "can't interpolate into string*");
}
static void simple_dict(void)