diff --git a/CHANGELOG.md b/CHANGELOG.md index d7456b4f..aa6b3214 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Expected: January 2025 ### Corrected Bugs +* Fixed: [string length validation doesn't work for the entry "" in case it has default value specified](https://github.com/clicon/clixon/issues/563) * Fixed: [SNMP: snmpwalk is slow and can timeout](https://github.com/clicon/clixon/issues/404) ## 7.2.0 diff --git a/lib/src/clixon_validate.c b/lib/src/clixon_validate.c index 9669e709..8b60ac20 100644 --- a/lib/src/clixon_validate.c +++ b/lib/src/clixon_validate.c @@ -1065,6 +1065,13 @@ xml_yang_validate_add(clixon_handle h, goto done; goto fail; } + if (cvtype != CGV_EMPTY && cvtype != CGV_VOID){ + if (cv_parse1("", cv, &reason) != 1){ + if (xret && netconf_bad_element_xml(xret, "application", yang_argument_get(yt), reason) < 0) + goto done; + goto fail; + } + } } else{ if (cv_parse1(body, cv, &reason) != 1){ diff --git a/test/test_type_range.sh b/test/test_type_range.sh index 8161effb..e704ef6d 100755 --- a/test/test_type_range.sh +++ b/test/test_type_range.sh @@ -103,6 +103,7 @@ module example{ } leaf lstring { type tstring; + default "somestring"; } /* here follows unlimited ints */ leaf rint8 { @@ -165,6 +166,7 @@ cat < $dclispec/clispec.cli merge @datamodel, cli_merge(); create @datamodel, cli_create(); show, cli_show_config("candidate", "text"); + validate("Validate changes"), cli_validate(); quit("Quit"), cli_quit(); EOF @@ -211,10 +213,11 @@ function testbuiltin(){ } # Type explicit typed range tests. -# Parameters: 1: type (eg uint8) -# 2: val OK -# 3: eval Invalid value -# 4: post (eg .000 - special for decimal64, others should have "") +# Parameters: +# 1: type (eg uint8) +# 2: val OK +# 3: eval Invalid value +# 4: post (eg .000 - special for decimal64, others should have "") function testrange(){ t=$1 val=$2 @@ -317,6 +320,13 @@ testrange decimal64 1 0 ".000" # test string with lengthlimit testrange string "012" "01234567890" "" +# see https://github.com/clicon/clixon/issues/563 +new "Netconf set empty string with 1.. range" +expectpart "$($clixon_cli -1f $cfg -l o set lstring \"\")" 0 "" + +new "Validate expect fail" +expectpart "$($clixon_cli -1f $cfg -l o validate)" 255 "String length 0 out of range: 1 - 10" + if [ $BE -ne 0 ]; then new "Kill backend" # Check if premature kill