From: Evgeny Bobkin Date: Tue, 23 Jul 2013 11:30:11 +0000 (+0200) Subject: scanner: Fix regression for the \x escape sequence X-Git-Tag: 0.21.1~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bd3365b160e1e14c8dacca41dc8e14aca9a6631e;p=thirdparty%2Fvala.git 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 --- diff --git a/tests/basic-types/escape-chars.vala b/tests/basic-types/escape-chars.vala index 6ff1662a6..6784671af 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 ab1628cc0..19eb5c4e1 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: