| 1 |
From 74c95ec5932c737d4fcb06b8646b0017364ada14 Mon Sep 17 00:00:00 2001 |
| 2 |
From: Mike Dalessio <[email protected]> |
| 3 |
Date: Fri, 24 Dec 2021 19:08:01 -0500 |
| 4 |
Subject: [PATCH] attempt to hack in wildcard namespaces to xpath |
| 5 |
|
| 6 |
I'm not confident this is a bulletproof patch. |
| 7 |
--- |
| 8 |
xpath.c | 24 ++++++++++++++++++------ |
| 9 |
1 file changed, 18 insertions(+), 6 deletions(-) |
| 10 |
|
| 11 |
diff --git a/xpath.c b/xpath.c |
| 12 |
index 1aa2f1a..c7f0885 100644 |
| 13 |
--- a/xpath.c |
| 14 |
+++ b/xpath.c |
| 15 |
@@ -146,6 +146,9 @@ |
| 16 |
#define XPATH_MAX_RECURSION_DEPTH 5000 |
| 17 |
#endif |
| 18 |
|
| 19 |
+#define WILDCARD_PREFIX "*" |
| 20 |
+#define IS_WILDCARD_PREFIX(p) xmlStrEqual((xmlChar*)WILDCARD_PREFIX, p) |
| 21 |
+ |
| 22 |
/* |
| 23 |
* TODO: |
| 24 |
* There are a few spots where some tests are done which depend upon ascii |
| 25 |
@@ -11073,12 +11076,15 @@ xmlXPathCompNodeTest(xmlXPathParserContextPtr ctxt, xmlXPathTestVal *test, |
| 26 |
SKIP_BLANKS; |
| 27 |
|
| 28 |
if ((name == NULL) && (CUR == '*')) { |
| 29 |
- /* |
| 30 |
- * All elements |
| 31 |
- */ |
| 32 |
NEXT; |
| 33 |
- *test = NODE_TEST_ALL; |
| 34 |
- return(NULL); |
| 35 |
+ if (CUR != ':') { |
| 36 |
+ /* |
| 37 |
+ * All elements |
| 38 |
+ */ |
| 39 |
+ *test = NODE_TEST_ALL; |
| 40 |
+ return(NULL); |
| 41 |
+ } |
| 42 |
+ name = xmlCharStrdup(WILDCARD_PREFIX); |
| 43 |
} |
| 44 |
|
| 45 |
if (name == NULL) |
| 46 |
@@ -11327,6 +11333,10 @@ xmlXPathCompStep(xmlXPathParserContextPtr ctxt) { |
| 47 |
} |
| 48 |
#endif |
| 49 |
if (CUR == '*') { |
| 50 |
+ if (NXT(1) == ':') { |
| 51 |
+ NEXT; |
| 52 |
+ name = xmlCharStrdup(WILDCARD_PREFIX); |
| 53 |
+ } |
| 54 |
axis = AXIS_CHILD; |
| 55 |
} else { |
| 56 |
if (name == NULL) |
| 57 |
@@ -12030,7 +12040,7 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt, |
| 58 |
/* |
| 59 |
* Setup namespaces. |
| 60 |
*/ |
| 61 |
- if (prefix != NULL) { |
| 62 |
+ if (prefix != NULL && !IS_WILDCARD_PREFIX(prefix)) { |
| 63 |
URI = xmlXPathNsLookup(xpctxt, prefix); |
| 64 |
if (URI == NULL) { |
| 65 |
xmlXPathReleaseObject(xpctxt, obj); |
| 66 |
@@ -12369,6 +12379,8 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt, |
| 67 |
{ |
| 68 |
XP_TEST_HIT |
| 69 |
} |
| 70 |
+ } else if (IS_WILDCARD_PREFIX(prefix)) { |
| 71 |
+ XP_TEST_HIT |
| 72 |
} else { |
| 73 |
if ((cur->ns != NULL) && |
| 74 |
(xmlStrEqual(URI, cur->ns->href))) |
| 75 |
-- |
| 76 |
2.31.0 |
| 77 |
|