Repository: groovy Updated Branches: refs/heads/master 49fae701c -> cf34f4c01
Forbid `"""` and `'''` quoting themselves at the end of string Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/cf34f4c0 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/cf34f4c0 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/cf34f4c0 Branch: refs/heads/master Commit: cf34f4c019f4db85e03508ce043f130fdf153ebe Parents: 49fae70 Author: danielsun1106 <[email protected]> Authored: Sat Mar 31 20:03:27 2018 +0800 Committer: danielsun1106 <[email protected]> Committed: Sat Mar 31 20:08:07 2018 +0800 ---------------------------------------------------------------------- src/antlr/GroovyLexer.g4 | 4 ++-- .../groovy/parser/antlr4/SyntaxErrorTest.groovy | 5 +++++ .../src/test/resources/core/String_01x.groovy | 8 ++++---- .../src/test/resources/fail/String_01x.groovy | 20 ++++++++++++++++++++ .../src/test/resources/fail/String_02x.groovy | 20 ++++++++++++++++++++ 5 files changed, 51 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/cf34f4c0/src/antlr/GroovyLexer.g4 ---------------------------------------------------------------------- diff --git a/src/antlr/GroovyLexer.g4 b/src/antlr/GroovyLexer.g4 index 78bbd69..9fc0f85 100644 --- a/src/antlr/GroovyLexer.g4 +++ b/src/antlr/GroovyLexer.g4 @@ -314,14 +314,14 @@ SqStringCharacter // character in the triple double quotation string. e.g. """a""" fragment TdqStringCharacter : ~["\\$] - | GStringQuotationMark { _input.LA(1) != '"' || _input.LA(2) != '"' || _input.LA(3) == '"' }? + | GStringQuotationMark { _input.LA(1) != '"' || _input.LA(2) != '"' || (_input.LA(3) == '"' && _input.LA(4) != '"') || (_input.LA(3) == '"' && _input.LA(5) != '"') }? | EscapeSequence ; // character in the triple single quotation string. e.g. '''a''' fragment TsqStringCharacter : ~['\\] - | SqStringQuotationMark { _input.LA(1) != '\'' || _input.LA(2) != '\'' || _input.LA(3) == '\'' }? + | SqStringQuotationMark { _input.LA(1) != '\'' || _input.LA(2) != '\'' || (_input.LA(3) == '\'' && _input.LA(4) != '\'') || (_input.LA(3) == '\'' && _input.LA(5) != '\'') }? | EscapeSequence ; http://git-wip-us.apache.org/repos/asf/groovy/blob/cf34f4c0/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy ---------------------------------------------------------------------- diff --git a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy index a956e4c..c23e8f4 100644 --- a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy +++ b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy @@ -217,6 +217,11 @@ class SyntaxErrorTest extends GroovyTestCase { TestUtils.doRunAndShouldFail('fail/Var_02x.groovy'); } + void "test groovy core - String"() { + TestUtils.doRunAndShouldFail('fail/String_01x.groovy'); + TestUtils.doRunAndShouldFail('fail/String_02x.groovy'); + } + /**************************************/ static unzipScriptAndShouldFail(String entryName, List ignoreClazzList, Map<String, String> replacementsMap=[:], boolean toCheckNewParserOnly = false) { ignoreClazzList.addAll(TestUtils.COMMON_IGNORE_CLASS_LIST) http://git-wip-us.apache.org/repos/asf/groovy/blob/cf34f4c0/subprojects/parser-antlr4/src/test/resources/core/String_01x.groovy ---------------------------------------------------------------------- diff --git a/subprojects/parser-antlr4/src/test/resources/core/String_01x.groovy b/subprojects/parser-antlr4/src/test/resources/core/String_01x.groovy index 8f9a5ca..636bb2d 100644 --- a/subprojects/parser-antlr4/src/test/resources/core/String_01x.groovy +++ b/subprojects/parser-antlr4/src/test/resources/core/String_01x.groovy @@ -17,7 +17,7 @@ * under the License. */ -def v = '''string='a'''' -assert v == '''string=\'a\'''' -def v2 = """string="a"""" -assert v2 == """string=\"a\"""" \ No newline at end of file +assert '''string=\'a\'''' == '''string='a'''' +assert """string=\"a\"""" == """string="a"""" +assert '''123\'\'''' == '''123''''' +assert """123\"\"""" == """123""""" \ No newline at end of file http://git-wip-us.apache.org/repos/asf/groovy/blob/cf34f4c0/subprojects/parser-antlr4/src/test/resources/fail/String_01x.groovy ---------------------------------------------------------------------- diff --git a/subprojects/parser-antlr4/src/test/resources/fail/String_01x.groovy b/subprojects/parser-antlr4/src/test/resources/fail/String_01x.groovy new file mode 100644 index 0000000..8e810de --- /dev/null +++ b/subprojects/parser-antlr4/src/test/resources/fail/String_01x.groovy @@ -0,0 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +def v = '''123'''''' \ No newline at end of file http://git-wip-us.apache.org/repos/asf/groovy/blob/cf34f4c0/subprojects/parser-antlr4/src/test/resources/fail/String_02x.groovy ---------------------------------------------------------------------- diff --git a/subprojects/parser-antlr4/src/test/resources/fail/String_02x.groovy b/subprojects/parser-antlr4/src/test/resources/fail/String_02x.groovy new file mode 100644 index 0000000..0476ff5 --- /dev/null +++ b/subprojects/parser-antlr4/src/test/resources/fail/String_02x.groovy @@ -0,0 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +def v2 = """123"""""" \ No newline at end of file
