From patchwork Wed Jan 2 14:05:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Fergeau X-Patchwork-Id: 1019990 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=208.118.235.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43VCX022dhz9s4s for ; Thu, 3 Jan 2019 01:06:24 +1100 (AEDT) Received: from localhost ([127.0.0.1]:44999 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gehA6-0006MW-5F for incoming@patchwork.ozlabs.org; Wed, 02 Jan 2019 09:06:22 -0500 Received: from eggs.gnu.org ([208.118.235.92]:47170) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1geh9c-0006LZ-0X for qemu-devel@nongnu.org; Wed, 02 Jan 2019 09:05:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1geh9Z-0001A9-1Q for qemu-devel@nongnu.org; Wed, 02 Jan 2019 09:05:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58758) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1geh9U-00015F-4F for qemu-devel@nongnu.org; Wed, 02 Jan 2019 09:05:44 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2BCAAC06512E for ; Wed, 2 Jan 2019 14:05:39 +0000 (UTC) Received: from natto.ory.fergeau.eu (unknown [10.41.1.13]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F1DEE1019632 for ; Wed, 2 Jan 2019 14:05:38 +0000 (UTC) Received: by natto.ory.fergeau.eu (Postfix, from userid 1000) id D527361F906; Wed, 2 Jan 2019 15:05:37 +0100 (CET) From: Christophe Fergeau To: qemu-devel@nongnu.org Date: Wed, 2 Jan 2019 15:05:35 +0100 Message-Id: <20190102140535.11512-1-cfergeau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 02 Jan 2019 14:05:39 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] json: Fix % handling when not interpolating X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" commit 8bca4613 added support for %% in json strings when interpolating, but in doing so, this broke handling of % when not interpolating as the '%' is skipped in both cases. This commit ensures we only try to handle %% when interpolating. Signed-off-by: Christophe Fergeau Reviewed-by: Eric Blake Tested-by: Richard W.M. Jones --- qobject/json-parser.c | 10 ++++++---- tests/check-qjson.c | 5 +++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/qobject/json-parser.c b/qobject/json-parser.c index 7a7ae9e8d1..d8eb210c0c 100644 --- a/qobject/json-parser.c +++ b/qobject/json-parser.c @@ -208,11 +208,13 @@ static QString *parse_string(JSONParserContext *ctxt, JSONToken *token) } break; case '%': - if (ctxt->ap && ptr[1] != '%') { - parse_error(ctxt, token, "can't interpolate into string"); - goto out; + if (ctxt->ap) { + if (ptr[1] != '%') { + parse_error(ctxt, token, "can't interpolate into string"); + goto out; + } + ptr++; } - ptr++; /* fall through */ default: cp = mod_utf8_codepoint(ptr, 6, &end); diff --git a/tests/check-qjson.c b/tests/check-qjson.c index d876a7a96e..fa2afccb0a 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -175,6 +175,11 @@ static void utf8_string(void) "\xCE\xBA\xE1\xBD\xB9\xCF\x83\xCE\xBC\xCE\xB5", "\xCE\xBA\xE1\xBD\xB9\xCF\x83\xCE\xBC\xCE\xB5", "\\u03BA\\u1F79\\u03C3\\u03BC\\u03B5", + }, + /* '%' character when not interpolating */ + { + "100%", + "100%", }, /* 2 Boundary condition test cases */ /* 2.1 First possible sequence of a certain length */