* Fixed: Autocli YANG patterns including " were not properly escaped: \"

This commit is contained in:
Olof hagsand 2022-01-19 14:52:32 +01:00
parent 77b4468eb3
commit 95f6fe8b1a
4 changed files with 23 additions and 17 deletions

View file

@ -106,6 +106,7 @@ Users may have to change how they access the system
### Corrected Bugs ### Corrected Bugs
* Fixed: Autocli YANG patterns including `"` were not properly escaped: `\"`
* Ensure auto-cli can be run with `CLICON_CLI_VARONLY=1` * Ensure auto-cli can be run with `CLICON_CLI_VARONLY=1`
* Strip constants in cli_dbxml * Strip constants in cli_dbxml
* rpc_callback_call(): Check if nrp parameter is NULL to avoid SEGV * rpc_callback_call(): Check if nrp parameter is NULL to avoid SEGV

View file

@ -332,6 +332,7 @@ yang2cli_var_range(yang_stmt *ys,
* @param[in] patterns Cvec of regexp patterns * @param[in] patterns Cvec of regexp patterns
* @param[out] cb Buffer where cligen code is written * @param[out] cb Buffer where cligen code is written
* @see cv_validate_pattern for netconf validate code * @see cv_validate_pattern for netconf validate code
* @note for cligen, need to escape " -> \"
*/ */
static int static int
yang2cli_var_pattern(clicon_handle h, yang2cli_var_pattern(clicon_handle h,
@ -343,32 +344,43 @@ yang2cli_var_pattern(clicon_handle h,
cg_var *cvp; cg_var *cvp;
char *pattern; char *pattern;
int invert; int invert;
char *posix; char *posix = NULL;
int i;
mode = clicon_yang_regexp(h); mode = clicon_yang_regexp(h);
cvp = NULL; /* Loop over compiled regexps */ cvp = NULL; /* Loop over compiled regexps */
while ((cvp = cvec_each(patterns, cvp)) != NULL){ while ((cvp = cvec_each(patterns, cvp)) != NULL){
pattern = cv_string_get(cvp); pattern = cv_string_get(cvp);
invert = cv_flag(cvp, V_INVERT); invert = cv_flag(cvp, V_INVERT);
cprintf(cb, " regexp:%s\"", invert?"!":"");
if (mode == REGEXP_POSIX){ if (mode == REGEXP_POSIX){
posix = NULL; posix = NULL;
if (regexp_xsd2posix(pattern, &posix) < 0) if (regexp_xsd2posix(pattern, &posix) < 0)
goto done; goto done;
cprintf(cb, " regexp:%s\"%s\"", for (i=0; i<strlen(posix); i++){
invert?"!":"", if (posix[i] == '\"')
posix); cbuf_append(cb, '\\');
cbuf_append(cb, posix[i]);
}
if (posix){ if (posix){
free(posix); free(posix);
posix = NULL; posix = NULL;
} }
} }
else else{
cprintf(cb, " regexp:%s\"%s\"", for (i=0; i<strlen(pattern); i++){
invert?"!":"", if (pattern[i] == '\"')
pattern); cbuf_append(cb, '\\');
cbuf_append(cb, pattern[i]);
}
}
cprintf(cb, "\"");
} }
retval = 0; retval = 0;
done: done:
if (posix)
free(posix);
return retval; return retval;
} }

View file

@ -28,7 +28,7 @@
</restconf> </restconf>
<autocli> <autocli>
<module-default>false</module-default> <module-default>false</module-default>
<list-keyword-default>kw-key</list-keyword-default> <list-keyword-default>kw-nokey</list-keyword-default>
<treeref-state-default>false</treeref-state-default> <treeref-state-default>false</treeref-state-default>
<edit-mode-default>list container</edit-mode-default> <edit-mode-default>list container</edit-mode-default>
<completion-default>true</completion-default> <completion-default>true</completion-default>

View file

@ -42,7 +42,7 @@ cat <<EOF > $cfg
<rule> <rule>
<name>openconfig1</name> <name>openconfig1</name>
<operation>enable</operation> <operation>enable</operation>
<module-name>openconfig-bgp</module-name> <module-name>clixon-example</module-name>
</rule> </rule>
<rule> <rule>
<name>openconfig2</name> <name>openconfig2</name>
@ -70,13 +70,6 @@ EOF
# Example system # Example system
cat <<EOF > $dir/startup_db cat <<EOF > $dir/startup_db
<config> <config>
<bgp xmlns="http://openconfig.net/yang/bgp">
<global>
<config>
<as>0</as> /* XXX */
</config>
</global>
</bgp>
<network-instances xmlns="http://openconfig.net/yang/network-instance"> <network-instances xmlns="http://openconfig.net/yang/network-instance">
<network-instance> <network-instance>
<name>default</name> <name>default</name>