From b19ad079c2fd8e7718e124bb143a22b82701fcca Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Tue, 27 Dec 2022 14:59:56 +0100 Subject: [PATCH] Ignore special characters preceding script commands --- CHANGELOG.md | 1 + .../mwscript/test_scripts.cpp | 28 +++++++++++++++++++ components/compiler/fileparser.cpp | 10 ++----- components/compiler/scanner.cpp | 21 ++++++++++++++ components/compiler/scanner.hpp | 1 + 5 files changed, 53 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9eb66475bb..7bf2bd7332 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Bug #6427: Enemy health bar disappears before damaging effect ends Bug #6645: Enemy block sounds align with animation instead of blocked hits Bug #6661: Saved games that have no preview screenshot cause issues or crashes + Bug #6807: Ultimate Galleon is not working properly Bug #6939: OpenMW-CS: ID columns are too short Bug #6949: Sun Damage effect doesn't work in quasi exteriors Bug #6964: Nerasa Dralor Won't Follow diff --git a/apps/openmw_test_suite/mwscript/test_scripts.cpp b/apps/openmw_test_suite/mwscript/test_scripts.cpp index 9b6741475b..03ad1cd7e8 100644 --- a/apps/openmw_test_suite/mwscript/test_scripts.cpp +++ b/apps/openmw_test_suite/mwscript/test_scripts.cpp @@ -441,6 +441,28 @@ messagebox,"this is a %g",a ,End,)mwscript"; + const std::string sIssue6807 = R"mwscript(---Begin issue6807 + +short a + +---------------------- ++++++++++++ +*************** +///////////////////// +????????? +@@@@@@@@ +~~~~~~~~~~~~~~~~~~ + +set a to 1 + +;------------------------------------------------------------------------------------------------------------------------------------------------------------- +; Collision Detection Check +------------------------------------------------------------------------------------------------------------------------------------------------------------- + +-+'\/.,><$@---!=\/?--------(){}------ show a + +End)mwscript"; + TEST_F(MWScriptTest, mwscript_test_invalid) { EXPECT_THROW(compile("this is not a valid script", true), Compiler::SourceException); @@ -859,4 +881,10 @@ messagebox,"this is a %g",a { EXPECT_FALSE(!compile(sIssue6380)); } + + TEST_F(MWScriptTest, mwscript_test_6807) + { + registerExtensions(); + EXPECT_FALSE(!compile(sIssue6807)); + } } \ No newline at end of file diff --git a/components/compiler/fileparser.cpp b/components/compiler/fileparser.cpp index a2570ac5df..18d245ad9a 100644 --- a/components/compiler/fileparser.cpp +++ b/components/compiler/fileparser.cpp @@ -94,16 +94,10 @@ namespace Compiler bool FileParser::parseSpecial(int code, const TokenLoc& loc, Scanner& scanner) { - // Ignore any junk special characters - if (mState == BeginState) - { - if (code != Scanner::S_newline) - reportWarning("Stray special character before begin statement", loc); - return true; - } - if (code == Scanner::S_newline) { + if (mState == BeginState) + return true; if (mState == BeginCompleteState) { // parse the script body diff --git a/components/compiler/scanner.cpp b/components/compiler/scanner.cpp index 6e0b4e8879..9739241416 100644 --- a/components/compiler/scanner.cpp +++ b/components/compiler/scanner.cpp @@ -27,6 +27,7 @@ namespace Compiler mLoc.mColumn = 0; ++mLoc.mLine; mLoc.mLiteral.clear(); + mIgnoreSpecial = true; } else { @@ -119,6 +120,7 @@ namespace Compiler } else if (c.isAlpha() || c == '_' || c == '"') { + mIgnoreSpecial = false; bool cont = false; if (scanName(c, parser, cont)) @@ -129,6 +131,7 @@ namespace Compiler } else if (c.isDigit()) { + mIgnoreSpecial = false; bool cont = false; bool scanned = mExpectName ? scanName(c, parser, cont) : scanInt(c, parser, cont); @@ -402,6 +405,23 @@ namespace Compiler if (c == '\n') special = S_newline; + else if (mIgnoreSpecial) + { + // Ignore junk special characters + TokenLoc loc = mLoc; + while (get(c)) + { + if (c.isAlpha() || c == '_' || c == '"' || c.isDigit() || c == ';' || c == '\n') + { + putback(c); + break; + } + c.appendTo(loc.mLiteral); + } + mErrorHandler.warning("Stray special character at start of line", loc); + cont = true; + return true; + } else if (c == '(' || c == '[') /// \todo option to disable the use of [ as alias for ( special = S_open; else if (c == ')' || c == ']') /// \todo option to disable the use of ] as alias for ) @@ -598,6 +618,7 @@ namespace Compiler , mTolerantNames(false) , mIgnoreNewline(false) , mExpectName(false) + , mIgnoreSpecial(true) { } diff --git a/components/compiler/scanner.hpp b/components/compiler/scanner.hpp index 2c8a64e31a..354ad9ebf1 100644 --- a/components/compiler/scanner.hpp +++ b/components/compiler/scanner.hpp @@ -195,6 +195,7 @@ namespace Compiler bool mTolerantNames; bool mIgnoreNewline; bool mExpectName; + bool mIgnoreSpecial; public: enum keyword