summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Wellnhofer <wellnhofer@aevum.de>2023-01-18 15:15:41 +0100
committerNick Wellnhofer <wellnhofer@aevum.de>2023-01-18 15:15:41 +0100
commit608c65bb8ebfc12763aee1cc1f3778e17d71596e (patch)
tree422cbba50365fe33e34e83ff61859f23b8111417
parentbbb2b8f1360ee75a306a4dd1dae9e055cfe20125 (diff)
downloadlibxml2-608c65bb8ebfc12763aee1cc1f3778e17d71596e.tar.gz
xpath: number('-') should return NaN
Fixes https://gitlab.gnome.org/GNOME/libxslt/-/issues/81
-rw-r--r--result/XPath/expr/functions4
-rw-r--r--test/XPath/expr/functions1
-rw-r--r--xpath.c6
3 files changed, 8 insertions, 3 deletions
diff --git a/result/XPath/expr/functions b/result/XPath/expr/functions
index e09eb4a4..4ff9c586 100644
--- a/result/XPath/expr/functions
+++ b/result/XPath/expr/functions
@@ -20,6 +20,10 @@ Expression: -number('abc')
Object is a number : NaN
========================
+Expression: number('-')
+Object is a number : NaN
+
+========================
Expression: floor(0.1)
Object is a number : 0
diff --git a/test/XPath/expr/functions b/test/XPath/expr/functions
index 00b9461f..6008a07f 100644
--- a/test/XPath/expr/functions
+++ b/test/XPath/expr/functions
@@ -3,6 +3,7 @@ false()
number("1.5")
number('abc')
-number('abc')
+number('-')
floor(0.1)
floor(-0.1)
floor(-0)
diff --git a/xpath.c b/xpath.c
index 313312e5..97aa2164 100644
--- a/xpath.c
+++ b/xpath.c
@@ -10001,13 +10001,13 @@ xmlXPathStringEvalNumber(const xmlChar *str) {
#endif
if (cur == NULL) return(0);
while (IS_BLANK_CH(*cur)) cur++;
- if ((*cur != '.') && ((*cur < '0') || (*cur > '9')) && (*cur != '-')) {
- return(xmlXPathNAN);
- }
if (*cur == '-') {
isneg = 1;
cur++;
}
+ if ((*cur != '.') && ((*cur < '0') || (*cur > '9'))) {
+ return(xmlXPathNAN);
+ }
#ifdef __GNUC__
/*