[recipes] Don't parse a space as a number
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes] Don't parse a space as a number
- Date: Sat, 27 May 2017 22:33:51 +0000 (UTC)
commit 10e0307cf80375efdd21b42f53dec4b8e399facd
Author: Matthias Clasen <mclasen redhat com>
Date: Sat May 27 18:19:19 2017 -0400
Don't parse a space as a number
This was unintentional. Add a test that covers this corner case.
src/gr-number.c | 3 ++-
tests/number-data/number1.expected | 6 +++++-
tests/number-data/number1.in | 3 +++
3 files changed, 10 insertions(+), 2 deletions(-)
---
diff --git a/src/gr-number.c b/src/gr-number.c
index e108d9b..9c6d153 100644
--- a/src/gr-number.c
+++ b/src/gr-number.c
@@ -233,7 +233,8 @@ parse_as_float (GrNumber *number,
value = g_strtod (*input, &end);
- if (end != NULL && !space_or_nul (end[0])) {
+ if (*input == end ||
+ (end != NULL && !space_or_nul (end[0]))) {
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
_("Could not parse %s as a float"), *input);
return FALSE;
diff --git a/tests/number-data/number1.expected b/tests/number-data/number1.expected
index 62b48ae..7db3f4b 100644
--- a/tests/number-data/number1.expected
+++ b/tests/number-data/number1.expected
@@ -291,10 +291,14 @@ REST '--2'
ERROR Could not parse --2 as a number
INPUT '10 11.12'
-REST '11.12'
+REST ' 11.12'
FRACTION 1
NUMERATOR 10
DENOMINATOR 1
VALUE 10
FORMATTED '10'
+INPUT ' '
+REST ' '
+ERROR Could not parse as a number
+
diff --git a/tests/number-data/number1.in b/tests/number-data/number1.in
index f1b5ed7..91a7d7c 100644
--- a/tests/number-data/number1.in
+++ b/tests/number-data/number1.in
@@ -44,3 +44,6 @@
1/2/3
--2
10 11.12
+
+# empty text
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]