Empty leaf values, eg <a></a> are now checked at vlidation.

This commit is contained in:
Olof hagsand 2019-04-10 17:35:36 +02:00
parent 4a1e0f2cbc
commit 881dd56ee1
5 changed files with 56 additions and 20 deletions

View file

@ -663,6 +663,7 @@ xml_yang_validate_add(cxobj *xt,
char *body;
int ret;
cxobj *x;
enum cv_type cvtype;
/* if not given by argument (overide) use default link
and !Node has a config sub-statement and it is false */
@ -688,17 +689,28 @@ xml_yang_validate_add(cxobj *xt,
/* In the union case, value is parsed as generic REST type,
* needs to be reparsed when concrete type is selected
*/
if ((body = xml_body(xt)) != NULL){
if ((body = xml_body(xt)) == NULL){
/* We do not allow ints to be empty. Otherwise NULL strings
* are considered as "" */
cvtype = cv_type_get(cv);
if (cv_isint(cvtype) || cvtype == CGV_BOOL || cvtype == CGV_DEC64){
if (netconf_bad_element(cbret, "application", yt->ys_argument, "Invalid NULL value") < 0)
goto done;
goto fail;
}
}
else{
if (cv_parse1(body, cv, &reason) != 1){
if (netconf_bad_element(cbret, "application", yt->ys_argument, reason) < 0)
goto done;
goto fail;
}
if ((ys_cv_validate(cv, yt, &reason)) != 1){
if (netconf_bad_element(cbret, "application", yt->ys_argument, reason) < 0)
goto done;
goto fail;
}
}
if ((ys_cv_validate(cv, yt, &reason)) != 1){
if (netconf_bad_element(cbret, "application", yt->ys_argument, reason) < 0)
goto done;
goto fail;
}
break;
default:

View file

@ -364,7 +364,7 @@ cv_validate1(cg_var *cv,
cg_var *cv2;
int retval2;
yang_stmt *yi = NULL;
char *str;
char *str = NULL;
int found;
char **vec = NULL;
int nvec;
@ -435,8 +435,9 @@ cv_validate1(cg_var *cv,
case CGV_STRING:
case CGV_REST:
if ((str = cv_string_get(cv)) == NULL)
break;
uu = strlen(str);
uu = 0; /* equal no string with empty string for range check */
else
uu = strlen(str);
rets = range_check(uu, cv1, cv2, uint64);
break;
default:
@ -470,29 +471,34 @@ cv_validate1(cg_var *cv,
case CGV_STRING:
case CGV_REST:
str = cv_string_get(cv);
/* Note, if there is no value, eg <s/>, str is NULL.
*/
if (restype){
if (strcmp(restype, "enumeration") == 0){
found = 0;
yi = NULL;
while ((yi = yn_each(yrestype, yi)) != NULL){
if (yi->ys_keyword != Y_ENUM)
continue;
if (strcmp(yi->ys_argument, str) == 0){
found++;
break;
if (str != NULL)
while ((yi = yn_each(yrestype, yi)) != NULL){
if (yi->ys_keyword != Y_ENUM)
continue;
if (strcmp(yi->ys_argument, str) == 0){
found++;
break;
}
}
}
if (!found){
if (reason)
*reason = cligen_reason("'%s' does not match enumeration", str);
goto fail;
}
}
if (strcmp(restype, "bits") == 0){
if (strcmp(restype, "bits") == 0 && str != NULL){
/* The lexical representation of the bits type is a space-separated list
* of the names of the bits that are set. A zero-length string thus
* represents a value where no bits are set.
*/
nvec = 0;
if ((vec = clicon_strsep(str, " \t", &nvec)) == NULL)
goto done;
for (i=0; i<nvec; i++){
@ -521,7 +527,7 @@ cv_validate1(cg_var *cv,
char *posix = NULL;
if (regexp_xsd2posix(pattern, &posix) < 0)
goto done;
if ((retval2 = match_regexp(str, posix)) < 0){
if ((retval2 = match_regexp(str?str:"", posix)) < 0){
clicon_err(OE_DB, 0, "match_regexp: %s", pattern);
return -1;
}
@ -536,8 +542,9 @@ cv_validate1(cg_var *cv,
}
}
break;
case CGV_ERR:
case CGV_VOID:
break; /* empty type OK */
case CGV_ERR:
retval = 0;
if (reason)
*reason = cligen_reason("Invalid cv");