From patchwork Fri Jan 22 10:37:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 25104 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:ab61:0:0:0:0:0 with SMTP id u88csp1058316ybi; Fri, 22 Jan 2021 02:37:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJyr4M+UiPXnvTgIIffu/0zBEmVKGJrN2uiUZIoC1B+GPhwtjLBNW6DQ+kAceFdUo+HbcnXa X-Received: by 2002:aa7:d401:: with SMTP id z1mr2653153edq.213.1611311877480; Fri, 22 Jan 2021 02:37:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611311877; cv=none; d=google.com; s=arc-20160816; b=hn+kzxVp50ZzPMQGq5Z6UDTn3vzjs+jbmJably+bAz8y0d4FpBCMi9uqGQQSn4EBzx W3HCURQLJAQgVmNPN1O295QgSitOrc/IUt/LIybVT/J92PubGblteuCgm45ECdb/eP4k 0Jmbpn64DniVu93zw+zidPzOgQyL7zKNGK2ehf5ghfCmM9GMYhNAjl6+nJD8nJXSIL/G K3EFMGNspNiZQlRmC4v+TXo72M58+hiBmmv3UH2w9Q9ujTwMvNaX8wL+MkMz6x3lPePG mwOjdvKhNmK9raiDjR74j3ZB/u3kXj2hh3Vl0Ag92BlyQBojFVdi9WuP/RM+LSNSxCFW dNhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=hLv2hw8f4OqCc+jG4cw5eSGJW2XizP70JCqurlxtJgs=; b=DMZjMuCRzJ31fe+AepQ6RCDPEplx+YSHj7kHpyNsMVTHjmRhdm04GeFo/Tfo3aRQSD Ft0Lyh5v8M6Xkuv7RANqOWmVN6YnG/H9xHo8ZtC2IugQoZVsouLgp5tReFYtzzJvXbO9 f3D/dtoatO4gHkjTYQY9SVk65M52KrbP5vuSEuJ6uyfFY4PuI269qtXxJdWQyDijcQrP po9as5OvN9ss6xBOQmuH8f36TKCu3GU+dDZ88GK5MKHYMhMqojzhA8NkjevGH/clOBzm Mq84S0ggqU1azYQHqHkSBjSl7EaRC7jm42wuECHvwz5KYl5Re3O0nLezuthVvzyoqlHX pD1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=ZMeqtfWZ; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id qh14si2884667ejb.360.2021.01.22.02.37.56; Fri, 22 Jan 2021 02:37:57 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=ZMeqtfWZ; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6A4E968A215; Fri, 22 Jan 2021 12:37:47 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0903D68A27A for ; Fri, 22 Jan 2021 12:37:40 +0200 (EET) Received: by mail-lj1-f173.google.com with SMTP id n11so5954612lji.5 for ; Fri, 22 Jan 2021 02:37:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=0tqesKxf9Q+k2/HqKtigHhunyL1BUuz0/niwUhS0CRo=; b=ZMeqtfWZqZzRepUsFFX+vEvFpo6OATO+Qnyrxmr1SzSe+mywNePxty3B95/yqgHHkn 6uwkfj7PvRes0H537eAlWIulTRayK7lRfNtihmhiqX5/AzScYloJqYBHSFe529mWgLkz FX4XWGAYq+B52/mv95ObFeQW/In+6NLtmoblX+coLlvRhZVy3gEUqghbaMV10sbH+DiO 2e0tOpkq0G1wmmoG2BLBqwRvi42hPraUWlAYJZjVygHWp6rkzV4i3WJEohANPSBCH78A 0mlmuUUMmbHr71W4aLOMSpe2eIqadb4conmvqWgBz8HaBl6pEPJY09lCTa7xUnKmEmQz JIqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0tqesKxf9Q+k2/HqKtigHhunyL1BUuz0/niwUhS0CRo=; b=LytpJASeEd/OWMCQLHQxnLyTx493ttAimxvQ5+1W6xjU6cmMRmAyQodCtyELy6ukCL 3e0jybj1ML5U564th+jD2GL6RDoFh0LoYedZTpLl80lDDjXmQSy6FD18ofsLsvImA1Ph 0X0Sgv/X+te5JaECZM7N9DoBWw8W7Bde1rVUxe9XNQgsMmT1iVhe7V3us89PwLyCdpU+ XrCCjD7EP3ehm2xYETl4ddEI1ie1M1x2MFb1ooPM/bKvpk0mLtQa5a2ytyJrGfR9E1H/ MHO/qxNQVzHHO4tDqgxIxlHQ9FBf6wIwCtcB/E1yqODHgZccUJq9fyeQ3HDlzb6TqsYM eYNA== X-Gm-Message-State: AOAM532QSDb4mTvYkEACbz5Gei888khs2y7MF84Xks9zZKpUW4FTuHu0 xam0YLBIZb1ZRLIU4jeNlmSIXQgb5RI= X-Received: by 2002:a2e:80d2:: with SMTP id r18mr857667ljg.453.1611311859465; Fri, 22 Jan 2021 02:37:39 -0800 (PST) Received: from localhost.localdomain (91-159-194-103.elisa-laajakaista.fi. [91.159.194.103]) by smtp.gmail.com with ESMTPSA id g2sm831626lfb.255.2021.01.22.02.37.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jan 2021 02:37:38 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Fri, 22 Jan 2021 12:37:32 +0200 Message-Id: <20210122103734.24420-3-jeebjp@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210122103734.24420-1-jeebjp@gmail.com> References: <20210122103734.24420-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 2/4] avutil/{avstring, bprint}: add XML attribute value escape modes X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: p0xLEtBhqQIS Content-Length: 6177 From: Jan Ekström Signed-off-by: Jan Ekström --- libavutil/avstring.h | 10 ++++++---- libavutil/bprint.c | 26 ++++++++++++++++++++++++++ tools/ffescape.c | 10 ++++++---- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/libavutil/avstring.h b/libavutil/avstring.h index 189b4726a5..c83aa9cf57 100644 --- a/libavutil/avstring.h +++ b/libavutil/avstring.h @@ -321,10 +321,12 @@ int av_match_name(const char *name, const char *names); char *av_append_path_component(const char *path, const char *component); enum AVEscapeMode { - AV_ESCAPE_MODE_AUTO, ///< Use auto-selected escaping mode. - AV_ESCAPE_MODE_BACKSLASH, ///< Use backslash escaping. - AV_ESCAPE_MODE_QUOTE, ///< Use single-quote escaping. - AV_ESCAPE_MODE_XML_CHAR_DATA, ///< Use XML non-markup character data escaping. + AV_ESCAPE_MODE_AUTO, ///< Use auto-selected escaping mode. + AV_ESCAPE_MODE_BACKSLASH, ///< Use backslash escaping. + AV_ESCAPE_MODE_QUOTE, ///< Use single-quote escaping. + AV_ESCAPE_MODE_XML_CHAR_DATA, ///< Use XML non-markup character data escaping. + AV_ESCAPE_MODE_XML_ATT_VALUE_SINGLE_QUOTED, ///< Use XML single quoted attribute value escaping. + AV_ESCAPE_MODE_XML_ATT_VALUE_DOUBLE_QUOTED, ///< Use XML double quoted attribute value escaping. }; /** diff --git a/libavutil/bprint.c b/libavutil/bprint.c index 7cdbb75095..c42ccdeee5 100644 --- a/libavutil/bprint.c +++ b/libavutil/bprint.c @@ -298,6 +298,32 @@ void av_bprint_escape(AVBPrint *dstbuf, const char *src, const char *special_cha } break; + case AV_ESCAPE_MODE_XML_ATT_VALUE_SINGLE_QUOTED: + /* escape XML single quoted attribute values as per 2.3 */ + /* "'" ([^<&'] | Reference)* "'" */ + for (; *src; src++) { + switch (*src) { + case '&' : av_bprintf(dstbuf, "%s", "&"); break; + case '<' : av_bprintf(dstbuf, "%s", "<"); break; + case '\'': av_bprintf(dstbuf, "%s", "'"); break; + default: av_bprint_chars(dstbuf, *src, 1); + } + } + break; + + case AV_ESCAPE_MODE_XML_ATT_VALUE_DOUBLE_QUOTED: + /* escape XML double quoted attribute values as per 2.3 */ + /* '"' ([^<&"] | Reference)* '"' */ + for (; *src; src++) { + switch (*src) { + case '&' : av_bprintf(dstbuf, "%s", "&"); break; + case '<' : av_bprintf(dstbuf, "%s", "<"); break; + case '"' : av_bprintf(dstbuf, "%s", """); break; + default: av_bprint_chars(dstbuf, *src, 1); + } + } + break; + /* case AV_ESCAPE_MODE_BACKSLASH or unknown mode */ default: /* \-escape characters */ diff --git a/tools/ffescape.c b/tools/ffescape.c index e18f1edaf9..c827e0b301 100644 --- a/tools/ffescape.c +++ b/tools/ffescape.c @@ -101,10 +101,12 @@ int main(int argc, char **argv) break; } case 'm': - if (!strcmp(optarg, "auto")) escape_mode = AV_ESCAPE_MODE_AUTO; - else if (!strcmp(optarg, "backslash")) escape_mode = AV_ESCAPE_MODE_BACKSLASH; - else if (!strcmp(optarg, "quote")) escape_mode = AV_ESCAPE_MODE_QUOTE; - else if (!strcmp(optarg, "xml_char_data")) escape_mode = AV_ESCAPE_MODE_XML_CHAR_DATA; + if (!strcmp(optarg, "auto")) escape_mode = AV_ESCAPE_MODE_AUTO; + else if (!strcmp(optarg, "backslash")) escape_mode = AV_ESCAPE_MODE_BACKSLASH; + else if (!strcmp(optarg, "quote")) escape_mode = AV_ESCAPE_MODE_QUOTE; + else if (!strcmp(optarg, "xml_char_data")) escape_mode = AV_ESCAPE_MODE_XML_CHAR_DATA; + else if (!strcmp(optarg, "xml_att_value_single_quoted")) escape_mode = AV_ESCAPE_MODE_XML_ATT_VALUE_SINGLE_QUOTED; + else if (!strcmp(optarg, "xml_att_value_double_quoted")) escape_mode = AV_ESCAPE_MODE_XML_ATT_VALUE_DOUBLE_QUOTED; else { av_log(NULL, AV_LOG_ERROR, "Invalid value '%s' for option -m, "