From 5e66506f0038657817cbc988b859dd9c60837d88 Mon Sep 17 00:00:00 2001 From: michaeloffner Date: Mon, 10 Jun 2024 22:27:09 +0000 Subject: [PATCH] LDEV-4892 - fixing regression with function listener --- .../expression/AbstrCFMLExprTransformer.java | 2 +- .../lucee/transformer/util/SourceCode.java | 14 +++++++++++++ loader/build.xml | 2 +- loader/pom.xml | 2 +- test/tickets/LDEV4892.cfc | 21 +++++++++++++++++++ 5 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 test/tickets/LDEV4892.cfc diff --git a/core/src/main/java/lucee/transformer/cfml/expression/AbstrCFMLExprTransformer.java b/core/src/main/java/lucee/transformer/cfml/expression/AbstrCFMLExprTransformer.java index dfbcb488c8..5e9184157b 100755 --- a/core/src/main/java/lucee/transformer/cfml/expression/AbstrCFMLExprTransformer.java +++ b/core/src/main/java/lucee/transformer/cfml/expression/AbstrCFMLExprTransformer.java @@ -1887,7 +1887,7 @@ private FunctionMember getFunctionMember(Data data, final ExprString name, boole } private Expression getListener(Data data) throws TemplateException { - if (!insideCase && tenaryContext != CTX_TENARY_MIDDLE && data.srcCode.forwardIfCurrent(':')) { + if (!insideCase && tenaryContext != CTX_TENARY_MIDDLE && data.srcCode.isPreviousIgnoreSpace(')') && data.srcCode.forwardIfCurrent(':')) { int pos = data.srcCode.getPos(); comments(data); Expression expr = assignOp(data); diff --git a/core/src/main/java/lucee/transformer/util/SourceCode.java b/core/src/main/java/lucee/transformer/util/SourceCode.java index 251ea679d5..dffd85ce4b 100755 --- a/core/src/main/java/lucee/transformer/util/SourceCode.java +++ b/core/src/main/java/lucee/transformer/util/SourceCode.java @@ -145,6 +145,20 @@ public boolean isPrevious(char c) { return lcText[pos - 1] == c; } + public boolean isPreviousIgnoreSpace(char c) { + int start = pos; + try { + while (isPrevious(' ')) { + pos--; + } + if (!hasPrevious()) return false; + return charAt(getPos() - 1) == c; + } + finally { + pos = start; + } + } + /** * is the character at the next position the same as the character provided by the input parameter */ diff --git a/loader/build.xml b/loader/build.xml index 50e0e5a4ba..d34c26f1c1 100644 --- a/loader/build.xml +++ b/loader/build.xml @@ -2,7 +2,7 @@ - + diff --git a/loader/pom.xml b/loader/pom.xml index ea4b2f62e8..e9ca991d1e 100644 --- a/loader/pom.xml +++ b/loader/pom.xml @@ -3,7 +3,7 @@ org.lucee lucee - 6.1.0.190-SNAPSHOT + 6.1.0.191-SNAPSHOT jar Lucee Loader Build diff --git a/test/tickets/LDEV4892.cfc b/test/tickets/LDEV4892.cfc new file mode 100644 index 0000000000..1a84d6ef85 --- /dev/null +++ b/test/tickets/LDEV4892.cfc @@ -0,0 +1,21 @@ +component extends="org.lucee.cfml.test.LuceeTestCase" { + function test() { + return "abc"; + } + function run( testResults, testBox ) { + describe("Testcase for LDEV-4892 - Invalid struct shorthand syntax", function() { + it( title="check syntax colon with space", body=function( currentSpec ) { + var x={ "#test()#" : function(){} }; + }); + it( title="check syntax colon no space", body=function( currentSpec ) { + var x={ "#test()#":function(){} }; + }); + it( title="check syntax colon no space", body=function( currentSpec ) { + var x={ "#test()#" = function(){} }; + }); + it( title="check syntax colon no space", body=function( currentSpec ) { + var x={ "#test()#"=function(){} }; + }); + }); + } +} \ No newline at end of file