From 58985b94679f38bcea15210dbe5dc6e95168ee2b Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Tue, 18 Dec 2012 15:11:27 +0100 Subject: Fix unicode escape sequence validation in strings. 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 --- src/qml/qml/parser/qqmljslexer.cpp | 7 +++++-- .../auto/qml/parserstress/tests/ecma/LexicalConventions/7.7.4.js | 2 -- tests/auto/qml/qmlmin/tst_qmlmin.cpp | 1 + tests/auto/qml/qqmlecmascript/data/stringParsing_error.5.qml | 9 +++++++++ tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 2 +- 5 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 tests/auto/qml/qqmlecmascript/data/stringParsing_error.5.qml diff --git a/src/qml/qml/parser/qqmljslexer.cpp b/src/qml/qml/parser/qqmljslexer.cpp index 508d7581be..532826f15c 100644 --- a/src/qml/qml/parser/qqmljslexer.cpp +++ b/src/qml/qml/parser/qqmljslexer.cpp @@ -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 diff --git a/tests/auto/qml/parserstress/tests/ecma/LexicalConventions/7.7.4.js b/tests/auto/qml/parserstress/tests/ecma/LexicalConventions/7.7.4.js index 92a04942c7..4a3173db6c 100644 --- a/tests/auto/qml/parserstress/tests/ecma/LexicalConventions/7.7.4.js +++ b/tests/auto/qml/parserstress/tests/ecma/LexicalConventions/7.7.4.js @@ -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" ); diff --git a/tests/auto/qml/qmlmin/tst_qmlmin.cpp b/tests/auto/qml/qmlmin/tst_qmlmin.cpp index 3cda6c0885..3fb51512d9 100644 --- a/tests/auto/qml/qmlmin/tst_qmlmin.cpp +++ b/tests/auto/qml/qmlmin/tst_qmlmin.cpp @@ -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 index 0000000000..563e01a995 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/stringParsing_error.5.qml @@ -0,0 +1,9 @@ + +import QtQuick 2.0 + +QtObject { + function code() { + var x = "\u000G"; + } +} + diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index fb6efcaf5d..baee10055b 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -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)); -- cgit v1.2.3