Fix unicode escape sequence validation in strings.
authorErik Verbruggen <erik.verbruggen@digia.com>
Tue, 18 Dec 2012 14:11:27 +0000 (15:11 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 8 Jan 2013 12:01:25 +0000 (13:01 +0100)
Give an error message when the sequence does not conform to the grammar.
Note that both \u and \x (without any numbers following it) are not
valid escape sequences in ECMA5.1.

Change-Id: I14348984c680b0ce86e05faad5630afc1e98cd02
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/qml/parser/qqmljslexer.cpp
tests/auto/qml/parserstress/tests/ecma/LexicalConventions/7.7.4.js
tests/auto/qml/qmlmin/tst_qmlmin.cpp
tests/auto/qml/qqmlecmascript/data/stringParsing_error.5.qml [new file with mode: 0644]
tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp

index 508d758..532826f 100644 (file)
@@ -659,8 +659,11 @@ again:
                 // unicode escape sequence
                 case 'u':
                     u = decodeUnicodeEscapeCharacter(&ok);
-                    if (! ok)
-                        u = _char;
+                    if (! ok) {
+                        _errorCode = IllegalUnicodeEscapeSequence;
+                        _errorMessage = QCoreApplication::translate("QQmlParser", "Illegal unicode escape sequence");
+                        return T_ERROR;
+                    }
                     break;
 
                 // hex escape sequence
index 92a0494..4a3173d 100644 (file)
@@ -155,10 +155,8 @@ new TestCase( SECTION, "\\o",    "o",        "\o" );
 new TestCase( SECTION, "\\p",    "p",        "\p" );
 new TestCase( SECTION, "\\q",    "q",        "\q" );
 new TestCase( SECTION, "\\s",    "s",        "\s" );
-new TestCase( SECTION, "\\u",    "u",        "\u" );
 
 new TestCase( SECTION, "\\w",    "w",        "\w" );
-new TestCase( SECTION, "\\x",    "x",        "\x" );
 new TestCase( SECTION, "\\y",    "y",        "\y" );
 new TestCase( SECTION, "\\z",    "z",        "\z" );
 
index 3cda6c0..3fb5151 100644 (file)
@@ -124,6 +124,7 @@ void tst_qmlmin::initTestCase()
     invalidFiles << "tests/auto/qml/qqmlecmascript/data/stringParsing_error.2.qml";
     invalidFiles << "tests/auto/qml/qqmlecmascript/data/stringParsing_error.3.qml";
     invalidFiles << "tests/auto/qml/qqmlecmascript/data/stringParsing_error.4.qml";
+    invalidFiles << "tests/auto/qml/qqmlecmascript/data/stringParsing_error.5.qml";
     invalidFiles << "tests/auto/qml/qqmlecmascript/data/numberParsing_error.1.qml";
     invalidFiles << "tests/auto/qml/qqmlecmascript/data/numberParsing_error.2.qml";
 }
diff --git a/tests/auto/qml/qqmlecmascript/data/stringParsing_error.5.qml b/tests/auto/qml/qqmlecmascript/data/stringParsing_error.5.qml
new file mode 100644 (file)
index 0000000..563e01a
--- /dev/null
@@ -0,0 +1,9 @@
+
+import QtQuick 2.0
+
+QtObject {
+    function code() {
+        var x = "\u000G";
+    }
+}
+
index fb6efca..baee100 100644 (file)
@@ -7364,7 +7364,7 @@ void tst_qqmlecmascript::numberParsing()
 
 void tst_qqmlecmascript::stringParsing()
 {
-    for (int i = 1; i < 5; ++i) {
+    for (int i = 1; i < 6; ++i) {
         QString file("stringParsing_error.%1.qml");
         file = file.arg(i);
         QQmlComponent component(&engine, testFileUrl(file));