[vala/staging: 3/3] scanner: Improve check of "\u" escape sequence
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging: 3/3] scanner: Improve check of "\u" escape sequence
- Date: Mon, 25 Nov 2019 21:51:28 +0000 (UTC)
commit 77fe44c8a4064a77f93ec79cd380a31a1d565b6f
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Mon Nov 25 22:04:33 2019 +0100
scanner: Improve check of "\u" escape sequence
tests/Makefile.am | 2 ++
tests/scanner/regex-escape-u-empty.test | 5 +++++
tests/scanner/string-escape-u-empty.test | 5 +++++
vala/valageniescanner.vala | 24 +++++++++++++++---------
vala/valascanner.vala | 24 +++++++++++++++---------
5 files changed, 42 insertions(+), 18 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1bc7c4206..8448e1002 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -570,6 +570,7 @@ TESTS = \
scanner/preprocessor-unexpected.test \
scanner/regex-escape-invalid.test \
scanner/regex-escape-u-digit-length.test \
+ scanner/regex-escape-u-empty.test \
scanner/regex-escape-x-digit-length.test \
scanner/regex-escape-x-empty.test \
scanner/regex-escape-x.vala \
@@ -578,6 +579,7 @@ TESTS = \
scanner/regex-multiple-s.test \
scanner/regex-multiple-x.test \
scanner/string-escape-u-digit-length.test \
+ scanner/string-escape-u-empty.test \
scanner/string-escape-x-digit-length.test \
scanner/string-escape-x-empty.test \
scanner/string-escape-x.vala \
diff --git a/tests/scanner/regex-escape-u-empty.test b/tests/scanner/regex-escape-u-empty.test
new file mode 100644
index 000000000..73f6a3252
--- /dev/null
+++ b/tests/scanner/regex-escape-u-empty.test
@@ -0,0 +1,5 @@
+Invalid Code
+
+void main () {
+ Regex foo = /\u/s;
+}
diff --git a/tests/scanner/string-escape-u-empty.test b/tests/scanner/string-escape-u-empty.test
new file mode 100644
index 000000000..3faa4bb80
--- /dev/null
+++ b/tests/scanner/string-escape-u-empty.test
@@ -0,0 +1,5 @@
+Invalid Code
+
+void main () {
+ string foo = "\u";
+}
diff --git a/vala/valageniescanner.vala b/vala/valageniescanner.vala
index e6a1631fd..b5ff25f6a 100644
--- a/vala/valageniescanner.vala
+++ b/vala/valageniescanner.vala
@@ -235,12 +235,14 @@ public class Vala.Genie.Scanner {
current++;
token_length_in_chars++;
int digit_length;
- for (digit_length = 0; digit_length < 4 && current <
end && current[0].isxdigit (); digit_length++) {
+ for (digit_length = 0; current < end &&
current[0].isxdigit (); digit_length++) {
current++;
token_length_in_chars++;
}
- if (digit_length != 4) {
- Report.error (get_source_reference
(token_length_in_chars), "\\u requires four hex digits");
+ if (digit_length < 1) {
+ Report.error (get_source_reference
(token_length_in_chars), "\\u used with no following hex digits");
+ } else if (digit_length < 4) {
+ Report.error (get_source_reference
(token_length_in_chars), "incomplete universal character name");
}
break;
case 'x':
@@ -763,12 +765,14 @@ public class Vala.Genie.Scanner {
current++;
token_length_in_chars++;
int digit_length;
- for (digit_length = 0; digit_length < 4 && current <
end && current[0].isxdigit (); digit_length++) {
+ for (digit_length = 0; current < end &&
current[0].isxdigit (); digit_length++) {
current++;
token_length_in_chars++;
}
- if (digit_length != 4) {
- Report.error (get_source_reference
(token_length_in_chars), "\\u requires four hex digits");
+ if (digit_length < 1) {
+ Report.error (get_source_reference
(token_length_in_chars), "\\u used with no following hex digits");
+ } else if (digit_length < 4) {
+ Report.error (get_source_reference
(token_length_in_chars), "incomplete universal character name");
}
break;
case 'x':
@@ -1341,12 +1345,14 @@ public class Vala.Genie.Scanner {
current++;
token_length_in_chars++;
int digit_length;
- for (digit_length = 0; digit_length < 4 && current <
end && current[0].isxdigit (); digit_length++) {
+ for (digit_length = 0; current < end &&
current[0].isxdigit (); digit_length++) {
current++;
token_length_in_chars++;
}
- if (digit_length != 4) {
- Report.error (get_source_reference
(token_length_in_chars), "\\u requires four hex digits");
+ if (digit_length < 1) {
+ Report.error (get_source_reference
(token_length_in_chars), "\\u used with no following hex digits");
+ } else if (digit_length < 4) {
+ Report.error (get_source_reference
(token_length_in_chars), "incomplete universal character name");
}
break;
case 'x':
diff --git a/vala/valascanner.vala b/vala/valascanner.vala
index 9153c4bc4..a2e76b4d5 100644
--- a/vala/valascanner.vala
+++ b/vala/valascanner.vala
@@ -220,12 +220,14 @@ public class Vala.Scanner {
current++;
token_length_in_chars++;
int digit_length;
- for (digit_length = 0; digit_length < 4 && current <
end && current[0].isxdigit (); digit_length++) {
+ for (digit_length = 0; current < end &&
current[0].isxdigit (); digit_length++) {
current++;
token_length_in_chars++;
}
- if (digit_length != 4) {
- Report.error (get_source_reference
(token_length_in_chars), "\\u requires four hex digits");
+ if (digit_length < 1) {
+ Report.error (get_source_reference
(token_length_in_chars), "\\u used with no following hex digits");
+ } else if (digit_length < 4) {
+ Report.error (get_source_reference
(token_length_in_chars), "incomplete universal character name");
}
break;
case 'x':
@@ -740,12 +742,14 @@ public class Vala.Scanner {
current++;
token_length_in_chars++;
int digit_length;
- for (digit_length = 0; digit_length < 4 && current <
end && current[0].isxdigit (); digit_length++) {
+ for (digit_length = 0; current < end &&
current[0].isxdigit (); digit_length++) {
current++;
token_length_in_chars++;
}
- if (digit_length != 4) {
- Report.error (get_source_reference
(token_length_in_chars), "\\u requires four hex digits");
+ if (digit_length < 1) {
+ Report.error (get_source_reference
(token_length_in_chars), "\\u used with no following hex digits");
+ } else if (digit_length < 4) {
+ Report.error (get_source_reference
(token_length_in_chars), "incomplete universal character name");
}
break;
case 'x':
@@ -1183,12 +1187,14 @@ public class Vala.Scanner {
current++;
token_length_in_chars++;
int digit_length;
- for (digit_length = 0; digit_length < 4 && current <
end && current[0].isxdigit (); digit_length++) {
+ for (digit_length = 0; current < end &&
current[0].isxdigit (); digit_length++) {
current++;
token_length_in_chars++;
}
- if (digit_length != 4) {
- Report.error (get_source_reference
(token_length_in_chars), "\\u requires four hex digits");
+ if (digit_length < 1) {
+ Report.error (get_source_reference
(token_length_in_chars), "\\u used with no following hex digits");
+ } else if (digit_length < 4) {
+ Report.error (get_source_reference
(token_length_in_chars), "incomplete universal character name");
}
break;
case 'x':
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]