Fixed: [CLI: Explicit api-path not encoded correctly](https://github.com/clicon/clixon/issues/504)

This commit is contained in:
Olof hagsand 2024-03-26 11:53:02 +01:00
parent 928d7d5b4d
commit b13320f1a1
3 changed files with 24 additions and 9 deletions

View file

@ -14,6 +14,7 @@ Expected: May 2024
### Corrected Bugs
* Fixed: [CLI: Explicit api-path not encoded correctly](https://github.com/clicon/clixon/issues/504)
* Fixed: [Startup and default of same object causes too-many-elements error](https://github.com/clicon/clixon/issues/503)
## 7.0.0

View file

@ -513,7 +513,7 @@ api_path_fmt_subst_list_key(cbuf *cb,
* cvv: foo, bar
* api_path: /subif-entry=foo,bar/subid
*
* "api-path" is "URI-encoded path expression" definition in RFC8040 3.5.3 (note only =%s)
* "api-path" is "URI-encoded path expression" definition in RFC8040 3.5.3 (note only =%s/=,%s)
*/
int
api_path_fmt2api_path(const char *api_path_fmt,
@ -524,7 +524,6 @@ api_path_fmt2api_path(const char *api_path_fmt,
{
int retval = -1;
char c;
char cprev;
int esc = 0;
int uri_encode = 0;
cbuf *cb = NULL;
@ -541,7 +540,6 @@ api_path_fmt2api_path(const char *api_path_fmt,
}
j = 1; /* j==0 is cli string */
len = strlen(api_path_fmt);
cprev = 0;
for (i=0; i<len; i++){
c = api_path_fmt[i];
if (esc){
@ -582,19 +580,22 @@ api_path_fmt2api_path(const char *api_path_fmt,
default:
break;
}
uri_encode = 0;
}
else if (c == '%'){
esc++;
if (cprev == '=')
uri_encode++;
}
else if ((c == '=' || c == ',') && api_path_fmt[i+1]=='%' && j == cvec_len(cvv))
else if ((c == '=' || c == ',') && api_path_fmt[i+1]=='%' && j == cvec_len(cvv)){
; /* skip */
else
}
else {
if (c == '=')
uri_encode++;
else if (c == '/')
uri_encode = 0;
cprintf(cb, "%c", c);
cprev = c;
}
}
if ((*api_path = strdup(cbuf_get(cb))) == NULL){
clixon_err(OE_UNIX, errno, "strdup");
goto done;

View file

@ -68,6 +68,7 @@ set x,cli_merge("/example:x");{
a <a:string> b <b:string>,cli_merge("/example:x/m1=%s,%s/");{
c <c:string>,cli_merge("/example:x/m1=%s,%s/c");
}
ax <a:string>("special case") c <c:string>,cli_merge("/example:x/m1=,%s/c");
}
# Negative
err x,cli_set("/example2:x");{
@ -105,6 +106,18 @@ expectpart "$($clixon_cli -1 -f $cfg set x a 22 b 33 c 55)" 0 ""
new "show conf x"
expectpart "$($clixon_cli -1 -f $cfg show conf x)" 0 "x m1 a 22 b 33"
new "set conf x, special case comma"
expectpart "$($clixon_cli -1 -f $cfg set x ax 11 c 33)" 0 "^$"
new "show conf ax"
expectpart "$($clixon_cli -1 -f $cfg show conf x)" 0 "x m1 a (null) b 11 c 33"
new "set conf x, special case comma encoding"
expectpart "$($clixon_cli -1 -f $cfg set x ax 22/22 c 44)" 0 "^$"
new "show conf ax"
expectpart "$($clixon_cli -1 -f $cfg show conf x)" 0 "x m1 a (null) b 22/22 c 44"
# Negative tests
new "err x"
expectpart "$($clixon_cli -1 -f $cfg -l n err x)" 255 "Config error: api-path syntax error \"/example2:x\": application unknown-element No such yang module prefix <bad-element>example2</bad-element>: Invalid argument"