[vala/0.40] genie: Add support for the \uXXXX escape sequence



commit d54a5720ae928fdcbaa1ade47037acaf731be178
Author: Evgeny Bobkin <evgen ibqn gmail com>
Date:   Wed May 16 14:15:07 2018 +0200

    genie: Add support for the \uXXXX escape sequence
    
    An additional checks to validate the escape sequences \xYY and \uYYYY
    were added, where Y represents a hex digit.
    
    Ported from 04422d716cf226b5e8a6c11306e07adbde26fd67

 vala/valageniescanner.vala |   63 +++++++++++++++++++++++++++++++++++++++----
 1 files changed, 57 insertions(+), 6 deletions(-)
---
diff --git a/vala/valageniescanner.vala b/vala/valageniescanner.vala
index 91d45b2..c72bb45 100644
--- a/vala/valageniescanner.vala
+++ b/vala/valageniescanner.vala
@@ -230,14 +230,31 @@ public class Vala.Genie.Scanner {
                                                        current++;
                                                        token_length_in_chars++;
                                                        break;
+                                               case 'u':
+                                                       // u escape character has four hex digits
+                                                       current++;
+                                                       token_length_in_chars++;
+                                                       int digit_length;
+                                                       for (digit_length = 0; digit_length < 4 && 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");
+                                                       }
+                                                       break;
                                                case 'x':
-                                                       // hexadecimal escape character
+                                                       // hexadecimal escape character requires two hex 
digits
                                                        current++;
                                                        token_length_in_chars++;
-                                                       while (current < end && current[0].isxdigit ()) {
+                                                       int digit_length;
+                                                       for (digit_length = 0; digit_length < 2 && 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");
+                                                       }
                                                        break;
                                                default:
                                                        // back references \1 through \99
@@ -739,14 +756,31 @@ public class Vala.Genie.Scanner {
                                                        current++;
                                                        token_length_in_chars++;
                                                        break;
+                                               case 'u':
+                                                       // u escape character has four hex digits
+                                                       current++;
+                                                       token_length_in_chars++;
+                                                       int digit_length;
+                                                       for (digit_length = 0; digit_length < 4 && 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");
+                                                       }
+                                                       break;
                                                case 'x':
-                                                       // hexadecimal escape character
+                                                       // hexadecimal escape character requires two hex 
digits
                                                        current++;
                                                        token_length_in_chars++;
-                                                       while (current < end && current[0].isxdigit ()) {
+                                                       int digit_length;
+                                                       for (digit_length = 0; digit_length < 2 && 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");
+                                                       }
                                                        break;
                                                default:
                                                        Report.error (get_source_reference 
(token_length_in_chars), "invalid escape sequence");
@@ -1295,14 +1329,31 @@ public class Vala.Genie.Scanner {
                                                        current++;
                                                        token_length_in_chars++;
                                                        break;
+                                               case 'u':
+                                                       // u escape character has four hex digits
+                                                       current++;
+                                                       token_length_in_chars++;
+                                                       int digit_length;
+                                                       for (digit_length = 0; digit_length < 4 && 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");
+                                                       }
+                                                       break;
                                                case 'x':
-                                                       // hexadecimal escape character
+                                                       // hexadecimal escape character requires two hex 
digits
                                                        current++;
                                                        token_length_in_chars++;
-                                                       while (current < end && current[0].isxdigit ()) {
+                                                       int digit_length;
+                                                       for (digit_length = 0; digit_length < 2 && 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");
+                                                       }
                                                        break;
                                                default:
                                                        Report.error (get_source_reference 
(token_length_in_chars), "invalid escape sequence");


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