xpath CHANGE provide more informative message in case of invalid XPath expression
diff --git a/src/common.h b/src/common.h
index 3a550b8..28d8d10 100644
--- a/src/common.h
+++ b/src/common.h
@@ -153,7 +153,7 @@
#define LY_VCODE_INDEV LYVE_SYNTAX_YANG, "Deviate \"%s\" does not support keyword \"%s\"."
#define LY_VCODE_INREGEXP LYVE_SYNTAX_YANG, "Regular expression \"%s\" is not valid (\"%s\": %s)."
#define LY_VCODE_XP_EOE LYVE_XPATH, "Unterminated string delimited with %c (%.15s)."
-#define LY_VCODE_XP_INEXPR LYVE_XPATH, "Invalid expression 0x%x."
+#define LY_VCODE_XP_INEXPR LYVE_XPATH, "Invalid character number %u of expression \'%s\'."
/******************************************************************************
* Context
diff --git a/src/xpath.c b/src/xpath.c
index 6e25cb9..94cb734 100644
--- a/src/xpath.c
+++ b/src/xpath.c
@@ -35,11 +35,12 @@
*
* @return Length of \p ncname valid bytes.
*/
-static size_t
+static long int
parse_ncname(const char *ncname)
{
unsigned int uc;
- size_t size, len = 0;
+ size_t size;
+ long int len = 0;
LY_CHECK_RET(ly_getutf8(&ncname, &uc, &size), 0);
if (!is_xmlqnamestartchar(uc) || (uc == ':')) {
@@ -51,7 +52,7 @@
if (!*ncname) {
break;
}
- LY_CHECK_RET(ly_getutf8(&ncname, &uc, &size), 0);
+ LY_CHECK_RET(ly_getutf8(&ncname, &uc, &size), -len);
} while (is_xmlqnamechar(uc) && (uc != ':'));
return len;
@@ -121,7 +122,8 @@
lyxp_expr_parse(struct ly_ctx *ctx, const char *expr)
{
struct lyxp_expr *ret;
- size_t parsed = 0, tok_len, ncname_len;
+ size_t parsed = 0, tok_len;
+ long int ncname_len;
enum lyxp_token tok_type;
int prev_function_check = 0;
@@ -308,7 +310,7 @@
expr[parsed], &expr[parsed], ret->tok_len[ret->used - 1], &ret->expr[ret->tok_pos[ret->used - 1]]);
goto error;
} else {
- LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_XP_INEXPR, expr[parsed], &expr[parsed]);
+ LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_XP_INEXPR, parsed + 1, expr);
goto error;
}
} else if (expr[parsed] == '*') {
@@ -321,7 +323,7 @@
/* NameTest (NCName ':' '*' | QName) or NodeType/FunctionName */
ncname_len = parse_ncname(&expr[parsed]);
- LY_CHECK_ERR_GOTO(!ncname_len, LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_XP_INEXPR, expr[parsed], &expr[parsed]), error);
+ LY_CHECK_ERR_GOTO(ncname_len < 0, LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_XP_INEXPR, parsed - ncname_len + 1, expr), error);
tok_len = ncname_len;
if (expr[parsed + tok_len] == ':') {
@@ -330,7 +332,7 @@
++tok_len;
} else {
ncname_len = parse_ncname(&expr[parsed + tok_len]);
- LY_CHECK_ERR_GOTO(!ncname_len, LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_XP_INEXPR, expr[parsed], &expr[parsed]), error);
+ LY_CHECK_ERR_GOTO(ncname_len < 0, LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_XP_INEXPR, parsed - ncname_len + 1, expr), error);
tok_len += ncname_len;
}
/* remove old flag to prevent ambiguities */