[augeas-devel] augeas: master - Change how names are parsed in path expressions

David Lutterkort lutter at fedoraproject.org
Fri Feb 6 21:56:27 UTC 2009


Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=e7e84ff1b0f0616b5c3017f4b4253af2fb4b54e0
Commit:        e7e84ff1b0f0616b5c3017f4b4253af2fb4b54e0
Parent:        b67cb02a063eb0dce5bbd97fa92714f93cbf711d
Author:        David Lutterkort <lutter at redhat.com>
AuthorDate:    Fri Feb 6 13:14:08 2009 -0800
Committer:     David Lutterkort <lutter at redhat.com>
CommitterDate: Fri Feb 6 13:29:01 2009 -0800

Change how names are parsed in path expressions

Names can not contain any of the characters [][=/ \t\n] - to include
them in a name, they need to be escaped with a '\', so that 'foo\=bar'
matches a node with literal label 'foo=bar'.
---
 doc/xpath.txt     |    2 +-
 src/pathx.c       |   21 +++++++++++++++++++--
 tests/xpath.tests |    2 +-
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/doc/xpath.txt b/doc/xpath.txt
index 92d9814..91381a6 100644
--- a/doc/xpath.txt
+++ b/doc/xpath.txt
@@ -120,7 +120,7 @@ MultiplicativeExpr ::= PathExpr ('*' PathExpr)*
 
 Literal ::= '"' /[^"]* / '"' | "'" /[^']* / "'"
 Number       ::= /[0-9]+/
-Name ::= /[^/\[ \t\n]+/
+Name ::= /([^][/\= \t\n]|\\.)+/
 
 
 Additional stuff
diff --git a/src/pathx.c b/src/pathx.c
index 0a0a3fe..8d9d14c 100644
--- a/src/pathx.c
+++ b/src/pathx.c
@@ -800,9 +800,17 @@ static char *parse_name(struct state *state) {
 
     while (*state->pos != '\0' &&
            *state->pos != L_BRACK && *state->pos != SEP &&
-           *state->pos != R_BRACK &&
-           !isspace(*state->pos))
+           *state->pos != R_BRACK && *state->pos != '=' &&
+           !isspace(*state->pos)) {
+        if (*state->pos == '\\') {
+            state->pos += 1;
+            if (*state->pos == '\0') {
+                STATE_ERROR(state, PATHX_ENAME);
+                return NULL;
+            }
+        }
         state->pos += 1;
+    }
 
     if (state->pos == s) {
         STATE_ERROR(state, PATHX_ENAME);
@@ -814,6 +822,15 @@ static char *parse_name(struct state *state) {
         STATE_ENOMEM;
         return NULL;
     }
+
+    char *p = result;
+    for (char *t = result; *t != '\0'; t++, p++) {
+        if (*t == '\\')
+            t += 1;
+        *p = *t;
+    }
+    *p = '\0';
+
     return result;
 }
 
diff --git a/tests/xpath.tests b/tests/xpath.tests
index 51f9824..7ab1f55 100644
--- a/tests/xpath.tests
+++ b/tests/xpath.tests
@@ -37,7 +37,7 @@ test self-nil-value /files/etc/hosts/*[value() = '']
      /files/etc/hosts/2
 
 # Match over two levels of the tree
-test two-wildcards /files/etc/*/*[ipaddr = '127.0.0.1']
+test two-wildcards /files/etc/*/*[ipaddr='127.0.0.1']
      /files/etc/hosts/1
 
 test pam-system-auth /files/etc/pam.d/*/*[module = 'system-auth']




More information about the augeas-devel mailing list