diff --git a/CHANGELOG.md b/CHANGELOG.md index 68a64201..7e40c94a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,6 +78,8 @@ * Added command-line option `-t ` for clixon_netconf - quit after max time. ### Corrected Bugs +* No space after ampersand escaped characters in XML https://github.com/clicon/clixon/issues/52 + * Thanks @SCadilhac * 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 diff --git a/lib/src/clixon_string.c b/lib/src/clixon_string.c index 0b0f73dd..480805fb 100644 --- a/lib/src/clixon_string.c +++ b/lib/src/clixon_string.c @@ -356,7 +356,7 @@ xml_chardata_encode(char **escp, else switch (str[i]){ case '&': - len += strlen("& "); + len += strlen("&"); break; case '<': if (strncmp(&str[i], "': - len += strlen("> "); + len += strlen(">"); break; default: len++; @@ -395,7 +395,7 @@ xml_chardata_encode(char **escp, else switch (str[i]){ case '&': - if ((l=snprintf(&esc[j], 7, "& ")) < 0){ + if ((l=snprintf(&esc[j], 6, "&")) < 0){ clicon_err(OE_UNIX, errno, "snprintf"); goto done; } @@ -407,14 +407,14 @@ xml_chardata_encode(char **escp, cdata++; break; } - if ((l=snprintf(&esc[j], 6, "< ")) < 0){ + if ((l=snprintf(&esc[j], 5, "<")) < 0){ clicon_err(OE_UNIX, errno, "snprintf"); goto done; } j += l; break; case '>': - if ((l=snprintf(&esc[j], 6, "> ")) < 0){ + if ((l=snprintf(&esc[j], 5, ">")) < 0){ clicon_err(OE_UNIX, errno, "snprintf"); goto done; } diff --git a/lib/src/clixon_xml_parse.l b/lib/src/clixon_xml_parse.l index c475417c..4e9b297a 100644 --- a/lib/src/clixon_xml_parse.l +++ b/lib/src/clixon_xml_parse.l @@ -113,11 +113,11 @@ int clixon_xml_parsewrap(void) . { clixon_xml_parselval.string = yytext; return CHARDATA; /*XXX:optimize*/} /* @see xml_chardata_encode */ -"amp; " { BEGIN(_YA->ya_lex_state); clixon_xml_parselval.string = "&"; return CHARDATA;} -"lt; " { BEGIN(_YA->ya_lex_state); clixon_xml_parselval.string = "<"; return CHARDATA;} -"gt; " { BEGIN(_YA->ya_lex_state); clixon_xml_parselval.string = ">"; return CHARDATA;} -"apos; " { BEGIN(_YA->ya_lex_state); clixon_xml_parselval.string = "'"; return CHARDATA;} -"quot; " { BEGIN(_YA->ya_lex_state); clixon_xml_parselval.string = "\""; return CHARDATA;} +"amp;" { BEGIN(_YA->ya_lex_state); clixon_xml_parselval.string = "&"; return CHARDATA;} +"lt;" { BEGIN(_YA->ya_lex_state); clixon_xml_parselval.string = "<"; return CHARDATA;} +"gt;" { BEGIN(_YA->ya_lex_state); clixon_xml_parselval.string = ">"; return CHARDATA;} +"apos;" { BEGIN(_YA->ya_lex_state); clixon_xml_parselval.string = "'"; return CHARDATA;} +"quot;" { BEGIN(_YA->ya_lex_state); clixon_xml_parselval.string = "\""; return CHARDATA;} . { clixon_xml_parselval.string = yytext; return CHARDATA;} \n { clixon_xml_parselval.string = yytext;_YA->ya_linenum++; return (CHARDATA);} diff --git a/test/test_netconf.sh b/test/test_netconf.sh index de312f68..ddb8cd3b 100755 --- a/test/test_netconf.sh +++ b/test/test_netconf.sh @@ -98,7 +98,7 @@ if [ $? -ne 0 ]; then fi new "netconf hello" -expecteof "$clixon_netconf -f $cfg -y $fyang" 0 ']]>]]>' '^urn:ietf:params:netconf:base:1.0urn: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]*]]>]]>]]>]]>$' +expecteof "$clixon_netconf -f $cfg -y $fyang" 0 ']]>]]>' '^urn:ietf:params:netconf:base:1.0urn: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 double quotes" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 ']]>]]>' '^]]>]]>$' @@ -183,10 +183,10 @@ new "netconf edit config merge" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "eth2ex:ethmerge]]>]]>" "^]]>]]>$" new "netconf edit ampersand encoding(<&): name:'eth&' type:'t<>'" -expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "eth& t< > ]]>]]>" "^]]>]]>$" +expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "eth&t<>]]>]]>" "^]]>]]>$" new "netconf get replaced config" -expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^eth& t< > trueeth1ex:ethtrueeth2ex:ethtrue]]>]]>$" +expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^eth&t<>trueeth1ex:ethtrueeth2ex:ethtrue]]>]]>$" new "cli show configuration eth& - encoding tests" expectfn "$clixon_cli -1 -f $cfg -y $fyang show conf cli" 0 "interfaces interface eth& type t<> diff --git a/test/test_xml.sh b/test/test_xml.sh index b24e9f70..b2937201 100755 --- a/test/test_xml.sh +++ b/test/test_xml.sh @@ -37,7 +37,7 @@ new "xml encode <>&" expecteof "$PROG" 0 "$XML" "^$XML$" XML=$(cat <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 " +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 " EOF ) new "xml optional encode single and double quote"