Skip to content

Commit a363411

Browse files
committed
Update unquoted tag expression handling
For a normal CFML tag an unquoted attribute, eg cfinput type=radio the string radio will be passed to the type attribute, if you have a variable named radio it will be ignored. However for a script mode tag cfinput(type=radio) it will use the radio variable instead.
1 parent 73b96ff commit a363411

5 files changed

Lines changed: 29 additions & 7 deletions

File tree

Statement.cfc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,12 @@ component accessors="false" {
313313
variables.attributeStruct[attributeName] = attributeValue;
314314
e = {expression=attributeValue, position=0};
315315
e.position = getStartPosition() + len(getName()) + i - len(attributeValue) + e.position;
316-
arrayAppend(variables.attributeExpressions, e);
316+
317+
if (isScriptModeTag()) {
318+
//only add to attributeExpressions if script as tag mode
319+
//in legacy / normal tags unquoted attributes are converted to strings
320+
arrayAppend(variables.attributeExpressions, e);
321+
}
317322
attributeName = "";
318323
mode = "new";
319324
attributeValue = "";
@@ -376,9 +381,12 @@ component accessors="false" {
376381
if (quotedValue == "" && bracketStack == 0 && parenStack == 0) {
377382
//end of unquoted expr value
378383
variables.attributeStruct[attributeName] = attributeValue;
379-
e = {expression=attributeValue, position=0};
380-
e.position = e.position + getStartPosition() + len(getName()) + (len(variables.attributeContent)- len(attributeValue));
381-
arrayAppend(variables.attributeExpressions, e);
384+
if (isScriptModeTag()) {
385+
//unquoted attr treated as expression in script mode tag, string in regular tags
386+
e = {expression=attributeValue, position=0};
387+
e.position = e.position + getStartPosition() + len(getName()) + (len(variables.attributeContent)- len(attributeValue));
388+
arrayAppend(variables.attributeExpressions, e);
389+
}
382390
}
383391
}
384392

box.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name":"cfmlparser",
3-
"version":"1.2.0",
3+
"version":"1.2.1",
44
"author":"Pete Freitag / Foundeo Inc.",
55
"location":"",
66
"directory":"",
@@ -42,7 +42,7 @@
4242
"contributors":[],
4343
"dependencies":{},
4444
"devDependencies":{
45-
"testbox":"^2.3"
45+
"testbox":"^6"
4646
},
4747
"installPaths":{
4848
"testbox":"tests/testbox/"

tests/tests/TestScriptParser.cfc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ component extends="BaseTest" {
8585
$assert.key(local.attribs, "value", "cfheader should have value attribute");
8686
$assert.isEqual("##boo##", local.attribs.value);
8787

88+
}
89+
if (stmt.getTagName() == "cfhttp") {
90+
local.attribs = stmt.getAttributes();
91+
$assert.isEqual("getMethod()", local.attribs.method);
92+
//should be an expression
93+
local.exprs = stmt.getExpressions();
94+
$assert.isEqual(1, arrayLen(local.exprs), "cfhttp tag should have 1 expression");
95+
$assert.isEqual("getMethod()", local.exprs[1].expression, "cfhttp tag should have 1 expression: getMethod()");
96+
8897
}
8998
if (stmt.isScriptModeTag()) {
9099
scriptModeTags++;

tests/tests/TestTag.cfc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ component extends="BaseTest" {
114114
$assert.isEqual(attr.url, "go.cfm");
115115
$assert.key(attr, "addtoken");
116116
$assert.isEqual(attr.addtoken, "false");
117+
$assert.isEqual(0, arrayLen(tag.getExpressions()), "Should be no expressions in plain tag mode here.");
117118

118119
}
119120

tests/tests/templates/script/tag.cfc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ component {
22

33
function onRequest() {
44
cfheader(name="foo", value="#boo#");
5-
cfhttp(url="address.cfm") {
5+
cfhttp(url="address.cfm", method=getMethod()) {
66
cfhttpparam(name="foo", value="moo", type="header");
77
}
88
}
9+
10+
function getMethod() {
11+
return "GET";
12+
}
913
}

0 commit comments

Comments
 (0)