From 7b2e775d80a26173761a44224066938b9c7e7d0b Mon Sep 17 00:00:00 2001 From: Zac Spitzer Date: Fri, 26 Jul 2024 18:03:29 +0200 Subject: [PATCH] LDEV-2646 ignore java docs comments inside a function https://luceeserver.atlassian.net/issues/LDEV-2646 --- .../expression/AbstrCFMLExprTransformer.java | 2 +- test/tickets/LDEV2646.cfc | 30 +++++++++---------- .../LDEV2646/ldev2646_doc_comments.cfc | 25 ++++++++++++++++ test/tickets/LDEV2646/obj.cfc | 14 --------- test/tickets/LDEV2646/test.cfm | 13 -------- 5 files changed, 40 insertions(+), 44 deletions(-) create mode 100644 test/tickets/LDEV2646/ldev2646_doc_comments.cfc delete mode 100644 test/tickets/LDEV2646/obj.cfc delete mode 100644 test/tickets/LDEV2646/test.cfm 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 c245d843f9..b8a6ab6589 100755 --- a/core/src/main/java/lucee/transformer/cfml/expression/AbstrCFMLExprTransformer.java +++ b/core/src/main/java/lucee/transformer/cfml/expression/AbstrCFMLExprTransformer.java @@ -2048,7 +2048,7 @@ private boolean multiLineComment(Data data) throws TemplateException { cfml.setPos(pos); throw new TemplateException(cfml, "comment is not closed"); } - if (isDocComment) { + if (isDocComment && !data.insideFunction) { String comment = cfml.substring(pos - 2, cfml.getPos() - pos); data.docComment = docCommentTransformer.transform(data.factory, comment); } diff --git a/test/tickets/LDEV2646.cfc b/test/tickets/LDEV2646.cfc index ee12781e00..ccf53b3b70 100644 --- a/test/tickets/LDEV2646.cfc +++ b/test/tickets/LDEV2646.cfc @@ -1,30 +1,28 @@ -component extends = "org.lucee.cfml.test.LuceeTestCase" labels="syntax" skip=true { +component extends = "org.lucee.cfml.test.LuceeTestCase" labels="syntax" { function beforeAll(){ - variables.uri = createURI("LDEV2646"); + pagePoolClear(); } function run( testResults, testBox ){ describe( "Test case for LDEV2646", function(){ it( title = "checking lock with comment line" , body = function( currentSpec ){ - local.result = _InternalRequest( - template : "#uri#\test.cfm", - form : { scene = 1} - ); - expect(trim(result.filecontent)).toBe(true); + var obj = createobject( "component", "LDEV2646.obj" ); + debug(obj); + expect( obj.testBadDocComment() ).toBeTrue(); + }); it( title = "checking lock without comment line" , body = function( currentSpec ){ - local.result = _InternalRequest( - template : "#uri#\test.cfm", - form : { scene = 2 } - ); - expect(trim(result.filecontent)).toBe(true); + var obj = createobject( "component", "LDEV2646.obj" ); + debug(obj.testGoodDocComment); + expect( obj.testGoodDocComment() ).toBeTrue(); + }); + + it( title = "checking lock no comment line" , body = function( currentSpec ){ + var obj = createobject( "component", "LDEV2646.obj" ); + expect( obj.testNoDocComment() ).toBeTrue(); }); }); } - private string function createURI(string calledName){ - var baseURI = "/test/#listLast(getDirectoryFromPath(getCurrenttemplatepath()),"\/")#/"; - return baseURI&""&calledName; - } } \ No newline at end of file diff --git a/test/tickets/LDEV2646/ldev2646_doc_comments.cfc b/test/tickets/LDEV2646/ldev2646_doc_comments.cfc new file mode 100644 index 0000000000..4ebc3e4c5d --- /dev/null +++ b/test/tickets/LDEV2646/ldev2646_doc_comments.cfc @@ -0,0 +1,25 @@ +/** + * I'm a test component + * @hint doc comments inside a function should be ignored! + */ +component name='testComponent' { + function testBadDocComment() { + /** If you delete this comment, all will be well! */ + lock name='test' timeout=1 type="exclusive" { + return true; + } + } + + function testGoodDocComment() { + /* I'm ok, as i'm on the second line */ + timer { + return true; + } + } + + function testNoDocComment() { + lock name='test' timeout=1 type="exclusive" { + return true; + } + } +} \ No newline at end of file diff --git a/test/tickets/LDEV2646/obj.cfc b/test/tickets/LDEV2646/obj.cfc deleted file mode 100644 index 081cb9abba..0000000000 --- a/test/tickets/LDEV2646/obj.cfc +++ /dev/null @@ -1,14 +0,0 @@ -component name='testComponent' { - function testLock() { - /** If you delete this comment, all will be well! */ - lock name='test' timeout=1 type="exclusive" { - return true; - } - } - - function testoneLock() { - lock name='test' timeout=1 type="exclusive" { - return true; - } - } -} \ No newline at end of file diff --git a/test/tickets/LDEV2646/test.cfm b/test/tickets/LDEV2646/test.cfm deleted file mode 100644 index b60028b36d..0000000000 --- a/test/tickets/LDEV2646/test.cfm +++ /dev/null @@ -1,13 +0,0 @@ - - param name="form.SCENE" default=""; - - obj = createobject("component","obj"); - if( form.scene eq 1 ){ - objTest = obj.testlock(); - writeoutput(objTest); - } - if( form.scene eq 2 ){ - objtestOne = obj.testonelock(); - writeoutput(objtestOne); - } - \ No newline at end of file