• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1From 608c65bb8ebfc12763aee1cc1f3778e17d71596e Mon Sep 17 00:00:00 2001
2From: Nick Wellnhofer <wellnhofer@aevum.de>
3Date: Wed, 18 Jan 2023 15:15:41 +0100
4Subject: [PATCH] xpath: number('-') should return NaN
5
6Fixes https://gitlab.gnome.org/GNOME/libxslt/-/issues/81
7
8Reference:https://github.com/GNOME/libxml2/commit/608c65bb8ebfc12763aee1cc1f3778e17d71596e
9Conflict:NA
10---
11 result/XPath/expr/functions | 4 ++++
12 test/XPath/expr/functions   | 1 +
13 xpath.c                     | 6 +++---
14 3 files changed, 8 insertions(+), 3 deletions(-)
15
16diff --git a/result/XPath/expr/functions b/result/XPath/expr/functions
17index e09eb4a..4ff9c58 100644
18--- a/result/XPath/expr/functions
19+++ b/result/XPath/expr/functions
20@@ -19,6 +19,10 @@ Object is a number : NaN
21 Expression: -number('abc')
22 Object is a number : NaN
23
24+========================
25+Expression: number('-')
26+Object is a number : NaN
27+
28 ========================
29 Expression: floor(0.1)
30 Object is a number : 0
31diff --git a/test/XPath/expr/functions b/test/XPath/expr/functions
32index 00b9461..6008a07 100644
33--- a/test/XPath/expr/functions
34+++ b/test/XPath/expr/functions
35@@ -3,6 +3,7 @@ false()
36 number("1.5")
37 number('abc')
38 -number('abc')
39+number('-')
40 floor(0.1)
41 floor(-0.1)
42 floor(-0)
43diff --git a/xpath.c b/xpath.c
44index 85d7919..fbec21b 100644
45--- a/xpath.c
46+++ b/xpath.c
47@@ -9987,13 +9987,13 @@ xmlXPathStringEvalNumber(const xmlChar *str) {
48 #endif
49     if (cur == NULL) return(0);
50     while (IS_BLANK_CH(*cur)) cur++;
51-    if ((*cur != '.') && ((*cur < '0') || (*cur > '9')) && (*cur != '-')) {
52-        return(xmlXPathNAN);
53-    }
54     if (*cur == '-') {
55 	isneg = 1;
56 	cur++;
57     }
58+    if ((*cur != '.') && ((*cur < '0') || (*cur > '9'))) {
59+        return(xmlXPathNAN);
60+    }
61
62 #ifdef __GNUC__
63     /*
64--
652.27.0
66
67