[gtk/matthiasc/for-master] css: Fix parsing of scientific notation
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/for-master] css: Fix parsing of scientific notation
- Date: Sat, 29 Aug 2020 16:44:37 +0000 (UTC)
commit 0f42d37f8bc7b6879be0a1b2766fc6119eb9f616
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Aug 29 12:12:09 2020 -0400
css: Fix parsing of scientific notation
The parser got its chars mixed up while parsing numbers
like 2.3e-04. While it is unlikely to meet such numbers
in human-generated css, we do have them e.g. when saving
render node trees with transforms.
Also add some css parser tests for number parsing.
gtk/css/gtkcsstokenizer.c | 7 +++----
testsuite/css/parser/number-values.css | 31 ++++++++++++++++++++++++++++++
testsuite/css/parser/number-values.ref.css | 31 ++++++++++++++++++++++++++++++
3 files changed, 65 insertions(+), 4 deletions(-)
---
diff --git a/gtk/css/gtkcsstokenizer.c b/gtk/css/gtkcsstokenizer.c
index 7aa3ff25e7..607c4d6992 100644
--- a/gtk/css/gtkcsstokenizer.c
+++ b/gtk/css/gtkcsstokenizer.c
@@ -1056,13 +1056,12 @@ gtk_css_tokenizer_read_numeric (GtkCssTokenizer *tokenizer,
}
}
- if (data + 1 < tokenizer->end && (*data == 'e' || *data == 'E') &&
- (g_ascii_isdigit (data[1]) ||
- (data + 2 < tokenizer->end && (data[1] == '+' || data[2] == '-') && g_ascii_isdigit (data[2]))))
+ if (data + 1 < tokenizer->end && (*data == 'e' || *data == 'E') &&
+ (g_ascii_isdigit (data[1]) ||
+ (data + 2 < tokenizer->end && (data[1] == '+' || data[1] == '-') && g_ascii_isdigit (data[2]))))
{
is_int = FALSE;
data++;
- exponent = g_ascii_digit_value (*data);
if (*data == '-')
{
diff --git a/testsuite/css/parser/number-values.css b/testsuite/css/parser/number-values.css
new file mode 100644
index 0000000000..6bb0ad02ba
--- /dev/null
+++ b/testsuite/css/parser/number-values.css
@@ -0,0 +1,31 @@
+a {
+ -gtk-dpi: 0;
+}
+
+b {
+ -gtk-dpi: 100;
+}
+
+c {
+ -gtk-dpi: -39;
+}
+
+d {
+ -gtk-dpi: 0.5;
+}
+
+e {
+ -gtk-dpi: 2.6e2;
+}
+
+f {
+ -gtk-dpi: 2.6E20;
+}
+
+g {
+ -gtk-dpi: 5e-1;
+}
+
+h {
+ -gtk-dpi: 2E-19;
+}
diff --git a/testsuite/css/parser/number-values.ref.css b/testsuite/css/parser/number-values.ref.css
new file mode 100644
index 0000000000..ba560741c4
--- /dev/null
+++ b/testsuite/css/parser/number-values.ref.css
@@ -0,0 +1,31 @@
+a {
+ -gtk-dpi: 0;
+}
+
+b {
+ -gtk-dpi: 100;
+}
+
+c {
+ -gtk-dpi: -39;
+}
+
+d {
+ -gtk-dpi: 0.5;
+}
+
+e {
+ -gtk-dpi: 260;
+}
+
+f {
+ -gtk-dpi: 2.6e+20;
+}
+
+g {
+ -gtk-dpi: 0.5;
+}
+
+h {
+ -gtk-dpi: 2e-19;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]