[vala] scanner: Fix regression for the \x escape sequence



commit bd3365b160e1e14c8dacca41dc8e14aca9a6631e
Author: Evgeny Bobkin <evgen ibqn gmail com>
Date:   Tue Jul 23 13:30:11 2013 +0200

    scanner: Fix regression for the \x escape sequence
    
    Allow a variable hex digit length for \x with a low boundary set to 1
    https://bugzilla.gnome.org/show_bug.cgi?id=704709

 tests/basic-types/escape-chars.vala |    7 ++++++-
 vala/valascanner.vala               |   18 +++++++++---------
 2 files changed, 15 insertions(+), 10 deletions(-)
---
diff --git a/tests/basic-types/escape-chars.vala b/tests/basic-types/escape-chars.vala
index 6ff1662..6784671 100644
--- a/tests/basic-types/escape-chars.vala
+++ b/tests/basic-types/escape-chars.vala
@@ -2,6 +2,11 @@ void test_x_escape_chars () {
        string s = "Copyright \xc2\xa9";
 
        assert (s == "Copyright ©");
+
+       // The escape sequence \x has a variable length
+       // with the lower boundary set to 1
+       string s1 = "\x9q";
+       assert (s1 == "\x09q");
 }
 
 void test_u_escape_chars () {
@@ -11,7 +16,7 @@ void test_u_escape_chars () {
 }
 
 void main () {
-       // Test case for bug report 704709
+       // Test case for the bug report 704709
        test_x_escape_chars ();
        test_u_escape_chars ();
 }
diff --git a/vala/valascanner.vala b/vala/valascanner.vala
index ab1628c..19eb5c4 100644
--- a/vala/valascanner.vala
+++ b/vala/valascanner.vala
@@ -230,12 +230,12 @@ public class Vala.Scanner {
                                                        current++;
                                                        token_length_in_chars++;
                                                        int digit_length;
-                                                       for (digit_length = 0; digit_length < 2 && 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 != 2) {
-                                                               Report.error (get_source_reference 
(token_length_in_chars), "\\x requires two hex digits");
+                                                       if (digit_length < 1) {
+                                                               Report.error (get_source_reference 
(token_length_in_chars), "\\x requires at least one hex digit");
                                                        }
                                                        break;
                                                default:
@@ -728,12 +728,12 @@ public class Vala.Scanner {
                                                        current++;
                                                        token_length_in_chars++;
                                                        int digit_length;
-                                                       for (digit_length = 0; digit_length < 2 && 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 != 2) {
-                                                               Report.error (get_source_reference 
(token_length_in_chars), "\\x requires two hex digits");
+                                                       if (digit_length < 1) {
+                                                               Report.error (get_source_reference 
(token_length_in_chars), "\\x requires at least one hex digit");
                                                        }
                                                        break;
                                                default:
@@ -1162,12 +1162,12 @@ public class Vala.Scanner {
                                                        current++;
                                                        token_length_in_chars++;
                                                        int digit_length;
-                                                       for (digit_length = 0; digit_length < 2 && 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 != 2) {
-                                                               Report.error (get_source_reference 
(token_length_in_chars), "\\x requires two hex digits");
+                                                       if (digit_length < 1) {
+                                                               Report.error (get_source_reference 
(token_length_in_chars), "\\x requires at least one hex digit");
                                                        }
                                                        break;
                                                default:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]