]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
scanner: Fix regression for the \x escape sequence
authorEvgeny Bobkin <evgen.ibqn@gmail.com>
Tue, 23 Jul 2013 11:30:11 +0000 (13:30 +0200)
committerEvgeny Bobkin <evgen.ibqn@gmail.com>
Tue, 23 Jul 2013 11:36:14 +0000 (13:36 +0200)
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
vala/valascanner.vala

index 6ff1662a696a759a3dfc3d7e2a596fb61b095d52..6784671af9e5715c7c231d9fab0d79376b02825f 100644 (file)
@@ -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 ();
 }
index ab1628cc0cc808b6f2e0f37f63a4526eb91452c9..19eb5c4e1d462446b7ea252a09411578dcd28afa 100644 (file)
@@ -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: