Skip to content

Commit fbb468c

Browse files
committed
Nested comment fix
1 parent 0d7e32d commit fbb468c

7 files changed

+91
-2
lines changed

TagParser.cfc

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ component extends="AbstractParser" {
142142
//no nested comments
143143
endTagPos = endTagPos+3;
144144
} else {
145-
nestedComment = 0;
145+
nestedComment = 1;
146146
while (charPos < contentLength) {
147147
c = mid(content, charPos,1);
148148
if (c == "<" && mid(content, charPos, 5) == "<!---") {

box.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name":"cfmlparser",
3-
"version":"1.1.8",
3+
"version":"1.1.9",
44
"author":"Pete Freitag / Foundeo Inc.",
55
"location":"",
66
"directory":"",

tests/tests/TestTagParser.cfc

+60
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,66 @@ component extends="BaseTest" {
5151

5252
}
5353

54+
function testNestedComment() {
55+
var parser = getParser("tag/nested-comment.cfm");
56+
var statements = parser.getStatements();
57+
var tag = "";
58+
59+
$assert.isTrue(isArray(statements), "getStatements returns array");
60+
$assert.isTrue(arrayLen(statements) == 1, "should have 1 elements: " & serializeJSON(statements));
61+
62+
tag = statements[1]; //should only have one comment element
63+
$assert.isTrue(tag.isComment(), "isComment");
64+
65+
}
66+
67+
function testNestedDoubleComment() {
68+
var parser = getParser("tag/nested-double-comment.cfm");
69+
var statements = parser.getStatements();
70+
var tag = "";
71+
72+
$assert.isTrue(isArray(statements), "getStatements returns array");
73+
$assert.isTrue(arrayLen(statements) == 2, "should have 2 elements: " & serializeJSON(statements));
74+
75+
tag = statements[1]; //should only have one comment element
76+
$assert.isTrue(tag.isComment(), "isComment");
77+
78+
tag = statements[2];
79+
$assert.isFalse(tag.isComment(), "second tag not a comment");
80+
$assert.isEqual("cfset", tag.getName());
81+
82+
}
83+
84+
function testNestedTripleComment() {
85+
var parser = getParser("tag/nested-triple-comment.cfm");
86+
var statements = parser.getStatements();
87+
var tag = "";
88+
89+
$assert.isTrue(isArray(statements), "getStatements returns array");
90+
$assert.isTrue(arrayLen(statements) == 2, "should have 2 elements: " & serializeJSON(statements));
91+
92+
tag = statements[1]; //should only have one comment element
93+
$assert.isTrue(tag.isComment(), "isComment");
94+
95+
tag = statements[2];
96+
$assert.isFalse(tag.isComment(), "second tag not a comment");
97+
$assert.isEqual("cfset", tag.getName());
98+
99+
}
100+
101+
function testUnclosedComment() {
102+
var parser = getParser("tag/unclosed-comment.cfm");
103+
var statements = parser.getStatements();
104+
var tag = "";
105+
106+
$assert.isTrue(isArray(statements), "getStatements returns array");
107+
$assert.isTrue(arrayLen(statements) == 1, "should have 1 elements: " & serializeJSON(statements));
108+
109+
tag = statements[1]; //should only have one comment element
110+
$assert.isTrue(tag.isComment(), "isComment");
111+
112+
}
113+
54114
function testGtInTag() {
55115
var parser = getParser("tag/gt-in-tag.cfm");
56116
var statements = parser.getStatements();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<!--- outer comment
2+
<!--- nested comment --->
3+
<cfquery>SELECT 1</cfquery>
4+
--->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!--- outer comment
2+
<!--- nested comment
3+
<!--- double comment --->
4+
<cfquery>SELECT 1</cfquery>
5+
6+
--->
7+
--->
8+
<cfset x = 1>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!--- outer comment
2+
<!--- nested comment
3+
<!--- another one --->
4+
<!--- double comment
5+
<!--- triple comment --->
6+
<cfquery>SELECT 1</cfquery>
7+
8+
--->
9+
<cfabort>
10+
<!--- one more --->
11+
--->
12+
--->
13+
<cfset x = 1>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<!---
2+
this comment is not closed
3+
<cfquery>SELECT 1</cfquery>
4+
so it should just look like one big comment

0 commit comments

Comments
 (0)