diff --git a/CHANGELOG.md b/CHANGELOG.md index 34ad35a8..96008d20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -94,6 +94,8 @@ * Added -l option for clixon_backend for directing syslog to stderr or stdout if running in foreground ### Corrected Bugs +* Single quotes for XML attributes https://github.com/clicon/clixon/issues/51 + * Thanks @SCadilhac * Fixed https://github.com/clicon/clixon/issues/46 Issue with empty values in leaf-list * Thanks achernavin22 * Identity without any identityref:s caused SEGV diff --git a/lib/src/clixon_xml_parse.l b/lib/src/clixon_xml_parse.l index 57000d0e..c475417c 100644 --- a/lib/src/clixon_xml_parse.l +++ b/lib/src/clixon_xml_parse.l @@ -89,17 +89,18 @@ int clixon_xml_parsewrap(void) return NAME; /* rather be catch-all */ } [ \t]+ ; -\: return *clixon_xml_parsetext; +\: return *clixon_xml_parsetext; \n { _YA->ya_linenum++;} ""/>" { BEGIN(STATEA); return ESLASH; } "" { BEGIN(START); return ECOMMENT; } -\n _YA->ya_linenum++; +\n _YA->ya_linenum++; . -encoding return ENC; -version return VER; -"=" return *clixon_xml_parsetext; -"?>" { BEGIN(START);return ETEXT;} -\" { BEGIN(STRDQ); return *clixon_xml_parsetext; } -\' { BEGIN(STRSQ); return *clixon_xml_parsetext; } +encoding return ENC; +version return VER; +"=" return *clixon_xml_parsetext; +"?>" { BEGIN(START);return ETEXT;} +\" { _YA->ya_lex_state =TEXTDECL;BEGIN(STRDQ); return *clixon_xml_parsetext; } +\' { _YA->ya_lex_state =TEXTDECL;BEGIN(STRSQ); return *clixon_xml_parsetext; } -[^\"]+ { clixon_xml_parselval.string = strdup(yytext); return CHARDATA; } -\" { BEGIN(START); return *clixon_xml_parsetext; } +1\.[0-9]+ { clixon_xml_parselval.string = strdup(yytext); return CHARDATA; } +[^\"]+ { clixon_xml_parselval.string = strdup(yytext); return CHARDATA; } +\" { BEGIN(_YA->ya_lex_state); return *clixon_xml_parsetext; } -1\.[0-9]+ { clixon_xml_parselval.string = strdup(yytext); return CHARDATA; } -[^\"]+ { clixon_xml_parselval.string = strdup(yytext); return CHARDATA; } -\" { BEGIN(TEXTDECL); return *clixon_xml_parsetext; } - -1\.[0-9]+ { clixon_xml_parselval.string = strdup(yytext); return CHARDATA; } -[^\']+ { clixon_xml_parselval.string = strdup(yytext); return CHARDATA; } -\' { BEGIN(TEXTDECL); return *clixon_xml_parsetext; } +1\.[0-9]+ { clixon_xml_parselval.string = strdup(yytext); return CHARDATA; } +[^\']+ { clixon_xml_parselval.string = strdup(yytext); return CHARDATA; } +\' { BEGIN(_YA->ya_lex_state); return *clixon_xml_parsetext; } %% diff --git a/lib/src/clixon_xml_parse.y b/lib/src/clixon_xml_parse.y index 8a80ff8d..ef9f78a9 100644 --- a/lib/src/clixon_xml_parse.y +++ b/lib/src/clixon_xml_parse.y @@ -401,6 +401,8 @@ attr : NAME '=' attvalue { if (xml_parse_attr(_YA, NULL, $1, $3) attvalue : '\"' CHARDATA '\"' { $$=$2; /* $2 must be consumed */} | '\"' '\"' { $$=strdup(""); /* $2 must be consumed */} + | '\'' CHARDATA '\'' { $$=$2; /* $2 must be consumed */} + | '\'' '\'' { $$=strdup(""); /* $2 must be consumed */} ; %% diff --git a/test/test_netconf.sh b/test/test_netconf.sh index 9f689dab..a4009b4c 100755 --- a/test/test_netconf.sh +++ b/test/test_netconf.sh @@ -100,8 +100,11 @@ fi new "netconf hello" expecteof "$clixon_netconf -f $cfg -y $fyang" 0 ']]>]]>' '^urn:ietf:params:netconf:base:1.1urn:ietf:params:netconf:capability:yang-library:1.0?revision="2016-06-21"& module-set-id=42urn:ietf:params:netconf:capability:candidate:1:0urn:ietf:params:netconf:capability:validate:1.1urn:ietf:params:netconf:capability:startup:1.0urn:ietf:params:netconf:capability:xpath:1.0urn:ietf:params:netconf:capability:notification:1.0[0-9]*]]>]]>]]>]]>$' -new "netconf get-config" -expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 ']]>]]>' '^]]>]]>$' +new "netconf get-config double quotes" +expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 ']]>]]>' '^]]>]]>$' + +new "netconf get-config single quotes" +expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" '^]]>]]>$' new "Add subtree eth/0/0 using none which should not change anything" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "noneeth/0/0]]>]]>" "^]]>]]>$" diff --git a/test/test_xml.sh b/test/test_xml.sh index 9550c402..d3a978ce 100755 --- a/test/test_xml.sh +++ b/test/test_xml.sh @@ -43,5 +43,11 @@ EOF new "xml optional encode single and double quote" expecteof "$PROG" 0 "$XML" "^To allow attribute values to contain both single and double quotes, the apostrophe or single-quote character ' may be represented as ' and the double-quote character as \"$" +new "Double quotes for attributes" +expecteof "$PROG" 0 '' '^$' + +new "Single quotes for attributes (returns double quotes but at least parses right)" +expecteof "$PROG" 0 "" '^$' + rm -rf $dir