From patchwork Mon Apr 19 18:48:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: david larsson X-Patchwork-Id: 28683 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 5778F27BC6C; Mon, 19 Apr 2021 19:54:54 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 5C05A27BC77 for ; Mon, 19 Apr 2021 19:54:52 +0100 (BST) Received: from localhost ([::1]:54344 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYZ2p-0002gD-EU for patchwork@mira.cbaines.net; Mon, 19 Apr 2021 14:54:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42126) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYYyA-0000ZT-51 for guix-patches@gnu.org; Mon, 19 Apr 2021 14:50:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:40532) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lYYy9-0006An-Tw for guix-patches@gnu.org; Mon, 19 Apr 2021 14:50:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lYYy9-0000DR-RU for guix-patches@gnu.org; Mon, 19 Apr 2021 14:50:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#47898] [PATCH] [core-updates] Add option --xpath0 to xmllint from libxml2 Resent-From: david larsson Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 19 Apr 2021 18:50:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 47898 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 47898@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.1618858155767 (code B ref -1); Mon, 19 Apr 2021 18:50:01 +0000 Received: (at submit) by debbugs.gnu.org; 19 Apr 2021 18:49:15 +0000 Received: from localhost ([127.0.0.1]:52078 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lYYxL-0000CG-IG for submit@debbugs.gnu.org; Mon, 19 Apr 2021 14:49:15 -0400 Received: from lists.gnu.org ([209.51.188.17]:50306) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lYYxG-0000C5-Sl for submit@debbugs.gnu.org; Mon, 19 Apr 2021 14:49:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41930) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYYxG-0008RR-81 for guix-patches@gnu.org; Mon, 19 Apr 2021 14:49:06 -0400 Received: from server0.selfhosted.xyz ([217.64.149.7]:41520) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYYxD-0005ha-A5 for guix-patches@gnu.org; Mon, 19 Apr 2021 14:49:05 -0400 Received: from server0.selfhosted.xyz (localhost [127.0.0.1]) by server0.selfhosted.xyz (Postfix) with ESMTP id 774481D40118 for ; Mon, 19 Apr 2021 20:48:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=selfhosted.xyz; s=dkim; t=1618858133; bh=0Oe4gdJQXyre2wMmvk/lPPyI7Ueu1zM9CBJ5m9TB93U=; h=Date:From:To:Subject; b=WA6lMnwYiVEV+TflkdoRzAgBWjsrNHdBpbDHJ684P29l8xBunyRGVUODr+1DHdpp6 1iUwaIhjDqFW+nmxG3wvTptGwUMj9ugQ3kQrgmVgtl9p8bfdRuvlmD006J4SfCBO4k xiHGOfw/Ztptp0m7KVyRqNqdsuJXL8YaEC2yBvF6Sh9g8X++kr/Nw+Yd0BknA7wfRN etxlPoXEu2izUMNaVouES1oOSqa5jtSaLrUnbLZIVsVl1UzJDXGntFznqTK6d8G1DW dB0XVlh+gQ14jiCoF8+fUZkRNikEk3AaIgKgDEPoAdWCTJnDFbsXg/yHGAWikp+PH/ 81i66q+vLbrww== X-Fuglu-Suspect: 289d4ab83d0f44bc978c971a664bca6d X-Fuglu-Spamstatus: NO Received: from webmail.selfhosted.xyz (office.selfhosted.xyz [192.168.1.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: mail@selfhosted.xyz) by server0.selfhosted.xyz (Postfix) with ESMTPSA for ; Mon, 19 Apr 2021 20:48:47 +0200 (CEST) MIME-Version: 1.0 Date: Mon, 19 Apr 2021 20:48:47 +0200 From: david larsson Message-ID: <20aec8da67d18b52e5a166f45cab40b2@selfhosted.xyz> X-Sender: david.larsson@selfhosted.xyz Received-SPF: pass client-ip=217.64.149.7; envelope-from=david.larsson@selfhosted.xyz; helo=server0.selfhosted.xyz X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FROM_SUSPICIOUS_NTLD=0.001, FROM_SUSPICIOUS_NTLD_FP=0.661, PDS_OTHER_BAD_TLD=1.999, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches Hi! This patch adds the option to separate xpath results from xmllint by a null delimiter when using the --xpath0 option-flag. It is something that's been asked for for a long time by users on stackoverflow and merge-attempts have been made to upstream without success. Examples: - https://gitlab.gnome.org/GNOME/libxml2/-/issues/227 - https://gitlab.gnome.org/GNOME/libxml2/-/merge_requests/8 Best regards, David From 714a6a26da55f7e06c94d3d2bb2965b9d2f832da Mon Sep 17 00:00:00 2001 From: David Larsson Date: Mon, 19 Apr 2021 20:39:23 +0200 Subject: [PATCH] gnu: libxml2: Add patch for xpath0 option to xmllint. * gnu/packages/patches/libxml2-Add-option-xpath0.patch: New file... * gnu/packages/xml.scm (libxml2) [source]: ...add it. --- .../patches/libxml2-Add-option-xpath0.patch | 139 ++++++++++++++++++ gnu/packages/xml.scm | 3 +- 2 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 gnu/packages/patches/libxml2-Add-option-xpath0.patch diff --git a/gnu/packages/patches/libxml2-Add-option-xpath0.patch b/gnu/packages/patches/libxml2-Add-option-xpath0.patch new file mode 100644 index 0000000000..3337374a8c --- /dev/null +++ b/gnu/packages/patches/libxml2-Add-option-xpath0.patch @@ -0,0 +1,139 @@ +From e1df743329bdfd94fbfdea18303c5c6c6fe13403 Mon Sep 17 00:00:00 2001 +From: methuselah-0 +Date: Thu, 1 Apr 2021 08:33:56 +0200 +Subject: [PATCH] Add option --xpath0 + +--- + doc/xmllint.xml | 16 ++++++++++++++++ + xmllint.c | 32 +++++++++++++++++++++++--------- + 2 files changed, 39 insertions(+), 9 deletions(-) + +diff --git a/doc/xmllint.xml b/doc/xmllint.xml +index 1008179b..fcdc237e 100644 +--- a/doc/xmllint.xml ++++ b/doc/xmllint.xml +@@ -70,6 +70,7 @@ + + + ++ + + + +@@ -537,6 +538,21 @@ + node set is serialized in full in the output. In case + of an empty node set the "XPath set is empty" result + will be shown and an error exit code will be returned. ++ Results are separated by the newline character. ++ ++ ++ ++ ++ ++ ++ ++ ++ Run an XPath expression given as argument and print the ++ result. In case of a nodeset result, each node in the ++ node set is serialized in full in the output. In case ++ of an empty node set the "XPath set is empty" result ++ will be shown and an error exit code will be returned. ++ Results are separated by the null character. + + + +diff --git a/xmllint.c b/xmllint.c +index 6ca1bf54..a60e1f4f 100644 +--- a/xmllint.c ++++ b/xmllint.c +@@ -194,6 +194,7 @@ static int sax1 = 0; + #endif /* LIBXML_SAX1_ENABLED */ + #ifdef LIBXML_XPATH_ENABLED + static const char *xpathquery = NULL; ++static const char *xpathsep = "\n"; + #endif + static int options = XML_PARSE_COMPACT | XML_PARSE_BIG_LINES; + static int sax = 0; +@@ -2095,7 +2096,7 @@ static void doXPathDump(xmlXPathObjectPtr cur) { + for (i = 0;i < cur->nodesetval->nodeNr;i++) { + node = cur->nodesetval->nodeTab[i]; + xmlNodeDumpOutput(buf, NULL, node, 0, 0, NULL); +- xmlOutputBufferWrite(buf, 1, "\n"); ++ xmlOutputBufferWrite(buf, 1, xpathsep); + } + xmlOutputBufferClose(buf); + #else +@@ -2104,27 +2105,27 @@ static void doXPathDump(xmlXPathObjectPtr cur) { + break; + } + case XPATH_BOOLEAN: +- if (cur->boolval) printf("true\n"); +- else printf("false\n"); ++ if (cur->boolval) printf("true%s", xpathsep); ++ else printf("false%s", xpathsep); + break; + case XPATH_NUMBER: + switch (xmlXPathIsInf(cur->floatval)) { + case 1: +- printf("Infinity\n"); ++ printf("Infinity%s", xpathsep); + break; + case -1: +- printf("-Infinity\n"); ++ printf("-Infinity%s", xpathsep); + break; + default: + if (xmlXPathIsNaN(cur->floatval)) { +- printf("NaN\n"); ++ printf("NaN%s", xpathsep); + } else { +- printf("%0g\n", cur->floatval); ++ printf("%0g%s", cur->floatval, xpathsep); + } + } + break; + case XPATH_STRING: +- printf("%s\n", (const char *) cur->stringval); ++ printf("%s%s", (const char *) cur->stringval, xpathsep); + break; + case XPATH_UNDEFINED: + fprintf(stderr, "XPath Object is uninitialized\n"); +@@ -3098,7 +3099,8 @@ static void usage(FILE *f, const char *name) { + fprintf(f, "\t--sax: do not build a tree but work just at the SAX level\n"); + fprintf(f, "\t--oldxml10: use XML-1.0 parsing rules before the 5th edition\n"); + #ifdef LIBXML_XPATH_ENABLED +- fprintf(f, "\t--xpath expr: evaluate the XPath expression, imply --noout\n"); ++ fprintf(f, "\t--xpath expr: evaluate the XPath expression, results are separated by \\n, imply --noout\n"); ++ fprintf(f, "\t--xpath0 expr: evaluate the XPath expression, results are separated by \\0, imply --noout\n"); + #endif + + fprintf(f, "\nLibxml project home page: http://xmlsoft.org/\n"); +@@ -3480,6 +3482,13 @@ main(int argc, char **argv) { + i++; + noout++; + xpathquery = argv[i]; ++ xpathsep = "\n"; ++ } else if ((!strcmp(argv[i], "-xpath0")) || ++ (!strcmp(argv[i], "--xpath0"))) { ++ i++; ++ noout++; ++ xpathquery = argv[i]; ++ xpathsep = "\0"; + #endif + } else if ((!strcmp(argv[i], "-oldxml10")) || + (!strcmp(argv[i], "--oldxml10"))) { +@@ -3712,6 +3721,11 @@ main(int argc, char **argv) { + i++; + continue; + } ++ if ((!strcmp(argv[i], "-xpath0")) || ++ (!strcmp(argv[i], "--xpath0"))) { ++ i++; ++ continue; ++ } + #endif + if ((timing) && (repeat)) + startTimer(); +-- +2.30.2 + diff --git a/gnu/packages/xml.scm b/gnu/packages/xml.scm index ad5f35ef1e..d6a9b46e1d 100644 --- a/gnu/packages/xml.scm +++ b/gnu/packages/xml.scm @@ -177,7 +177,8 @@ hierarchical form with variable field lengths.") version ".tar.gz")) (sha256 (base32 - "07xynh8hcxb2yb1fs051xrgszjvj37wnxvxgsj10rzmqzy9y3zma")))) + "07xynh8hcxb2yb1fs051xrgszjvj37wnxvxgsj10rzmqzy9y3zma")) + (patches (list (search-patch "libxml2-Add-option-xpath0.patch"))))) (build-system gnu-build-system) (outputs '("out" "static" "doc")) (arguments -- 2.30.2