* Fixed: Yang patterns: \n and other non-printable characters were broken
* Example: Clixon interpereted them two characters: `\\ n` instead of ascii 10
This commit is contained in:
parent
603f9724ce
commit
dcaeb581a1
5 changed files with 107 additions and 0 deletions
|
|
@ -56,6 +56,8 @@ Users may have to change how they access the system
|
||||||
|
|
||||||
### Corrected Bugs
|
### Corrected Bugs
|
||||||
|
|
||||||
|
* Fixed: Yang patterns: \n and other non-printable characters were broken
|
||||||
|
* Example: Clixon interpereted them two characters: `\\ n` instead of ascii 10
|
||||||
* Fixed: The auto-cli identityref did not expand identities in grouping/usecases properly.
|
* Fixed: The auto-cli identityref did not expand identities in grouping/usecases properly.
|
||||||
* Fixed: [OpenConfig BGP afi-safi and when condition issues #249](https://github.com/clicon/clixon/issues/249)
|
* Fixed: [OpenConfig BGP afi-safi and when condition issues #249](https://github.com/clicon/clixon/issues/249)
|
||||||
* YANG when was not properly implemented for default values
|
* YANG when was not properly implemented for default values
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,8 @@ int xml_chardata_encode(char **escp, const char *fmt, ...);
|
||||||
#endif
|
#endif
|
||||||
int xml_chardata_cbuf_append(cbuf *cb, char *str);
|
int xml_chardata_cbuf_append(cbuf *cb, char *str);
|
||||||
int uri_percent_decode(char *enc, char **str);
|
int uri_percent_decode(char *enc, char **str);
|
||||||
|
int nonprint_encode(char *orig, char **encp);
|
||||||
|
|
||||||
const char *clicon_int2str(const map_str2int *mstab, int i);
|
const char *clicon_int2str(const map_str2int *mstab, int i);
|
||||||
int clicon_str2int(const map_str2int *mstab, char *str);
|
int clicon_str2int(const map_str2int *mstab, char *str);
|
||||||
int clicon_str2int_search(const map_str2int *mstab, char *str, int upper);
|
int clicon_str2int_search(const map_str2int *mstab, char *str, int upper);
|
||||||
|
|
|
||||||
|
|
@ -646,6 +646,83 @@ uri_str2cvec(char *string,
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Translate \n and others from \\n (two chars) to \n (one char)
|
||||||
|
*
|
||||||
|
* This is needed in yang regex it seems.
|
||||||
|
* It was triggered by eg draft-wwlh-netconf-list-pagination-00 module example-social tagline
|
||||||
|
* leaf tagline {
|
||||||
|
* type string {
|
||||||
|
* length "1..80";
|
||||||
|
* pattern '.*[\n].*' {
|
||||||
|
* modifier invert-match;
|
||||||
|
* @param[in] orig Original string eg with \\n
|
||||||
|
* @param[out] enc Encoded string with \n, malloced.
|
||||||
|
*
|
||||||
|
* @see https://www.regular-expressions.info/nonprint.html
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
nonprint_encode(char *orig,
|
||||||
|
char **encp)
|
||||||
|
{
|
||||||
|
int retval = -1;
|
||||||
|
char *enc = NULL;
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
int esc = 0;
|
||||||
|
char c;
|
||||||
|
char c1;
|
||||||
|
|
||||||
|
if (orig == NULL){
|
||||||
|
clicon_err(OE_UNIX, EINVAL, "orig is NULL");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
/* Encoded string is equal or shorter */
|
||||||
|
if ((enc = malloc(strlen(orig)+1)) == NULL){
|
||||||
|
clicon_err(OE_UNIX, errno, "strdup");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
j = 0;
|
||||||
|
for (i=0; i<strlen(orig); i++){
|
||||||
|
c = orig[i];
|
||||||
|
switch (c){
|
||||||
|
case '\\':
|
||||||
|
/* Look ahead */
|
||||||
|
if (i+1 < strlen(orig)){
|
||||||
|
c1 = orig[i+1];
|
||||||
|
switch (c1){
|
||||||
|
case 'n':
|
||||||
|
enc[j++] = '\n';
|
||||||
|
esc++;
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
enc[j++] = '\t';
|
||||||
|
esc++;
|
||||||
|
break;
|
||||||
|
case 'r':
|
||||||
|
enc[j++] = '\r';
|
||||||
|
esc++;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
enc[j++] = c;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (esc)
|
||||||
|
esc = 0;
|
||||||
|
else
|
||||||
|
enc[j++] = c;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
enc[j++] = '\0';
|
||||||
|
*encp = enc;
|
||||||
|
retval = 0;
|
||||||
|
done:
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
/*! Map from int to string using str2int map
|
/*! Map from int to string using str2int map
|
||||||
* @param[in] ms String, integer map
|
* @param[in] ms String, integer map
|
||||||
* @param[in] i Input integer
|
* @param[in] i Input integer
|
||||||
|
|
|
||||||
|
|
@ -1896,6 +1896,18 @@ ys_parse_sub(yang_stmt *ys,
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case Y_PATTERN:{
|
||||||
|
char *s0;
|
||||||
|
char *s1 = NULL;
|
||||||
|
/* Replace \\n with \n */
|
||||||
|
s0 = yang_argument_get(ys);
|
||||||
|
if (nonprint_encode(s0, &s1) < 0)
|
||||||
|
goto done;
|
||||||
|
yang_argument_set(ys, s1);
|
||||||
|
if (s0)
|
||||||
|
free(s0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case Y_UNKNOWN:{ /* save (optional) argument in ys_cv */
|
case Y_UNKNOWN:{ /* save (optional) argument in ys_cv */
|
||||||
if (extra == NULL)
|
if (extra == NULL)
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -368,6 +368,15 @@ module pattern{
|
||||||
'[0-9]|25[0-5])$';
|
'[0-9]|25[0-5])$';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
leaf p47 {
|
||||||
|
description "draft-wwlh-netconf-list-pagination-00 module example-social";
|
||||||
|
type string {
|
||||||
|
length "1..80";
|
||||||
|
pattern '.*[\n].*' {
|
||||||
|
modifier invert-match;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
@ -741,6 +750,11 @@ testrun "p$pnr" true '255.149.90.121'
|
||||||
testrun "p$pnr" true '251.148.80.69'
|
testrun "p$pnr" true '251.148.80.69'
|
||||||
testrun "p$pnr" false '248:197.7.89/8'
|
testrun "p$pnr" false '248:197.7.89/8'
|
||||||
|
|
||||||
|
let pnr=47 # '.*[\n].*
|
||||||
|
testrun "p$pnr" true 'Ensure all nights are cold'
|
||||||
|
testrun "p$pnr" false 'kalle
foo'
|
||||||
|
testrun "p$pnr" false '01234567890123456789012345678901234567890123456789012345678901234567890123456789zzz'
|
||||||
|
|
||||||
# CLI tests
|
# CLI tests
|
||||||
new "CLI tests for RFC7950 Sec 9.4.7 ex 2 AB"
|
new "CLI tests for RFC7950 Sec 9.4.7 ex 2 AB"
|
||||||
expectpart "$($clixon_cli -1f $cfg -l o set c rfc2 AB)" 0 '^$'
|
expectpart "$($clixon_cli -1f $cfg -l o set c rfc2 AB)" 0 '^$'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue