Skip to content

Commit

Permalink
LDEV-5378 test case for cfprocessing directive (#2520)
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitzer authored Mar 6, 2025
1 parent 99f6c60 commit 8f2ba4a
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 0 deletions.
71 changes: 71 additions & 0 deletions test/tags/ProcessingDirective.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
component extends="org.lucee.cfml.test.LuceeTestCase" {

function run() {
describe("Tests for cfprocessingdirective", function() {

it("should correctly set page encoding", function() {
var result = _InternalRequest(template="#createURI('processingDirective')#/cfprocessingdirective_encoding.cfm");
debug(result);
expect(result.fileContent.trim()).toBe("Encoding set to UTF-8");
});

// ACF 2023 doesn't seem to strip whitespace at all?
it("should suppress whitespace when specified", function() {
var result = _InternalRequest(template="#createURI('processingDirective')#/cfprocessingdirective_whitespace.cfm");
var text = replace(
replace(
replace(result.fileContent,chr(10),"LF","all"),
chr(13),"CR","all"),
" ",".","all"
);
// test file is LF
expect( text ).toBe( "LFLFLine1LFLine2LFLine3LF" );
});
});

// disabled hangs https://luceeserver.atlassian.net/browse/LDEV-5378

xdescribe("Tests for cfprocessingdirective - preservecase", function() {

it("should preserve case when enabled", function() {
var result = _InternalRequest(
template="#createURI('processingDirective')#/cfprocessingdirective_preservecase.cfm",
url: {
preserve: true
}
);
expect(result.fileContent).toBeWithCase('{"camelCase":true}');
});

it("shouldn't preserve case when disabled", function() {
var result = _InternalRequest(
template="#createURI('processingDirective')#/cfprocessingdirective_preservecase.cfm",
url: {
preserve: false
}
);
expect(result.fileContent).toBeWithCase('{"CAMELCASE":false}');
});

it("shouldn't preserve case by default, no processingdirective", function() {
var result = _InternalRequest(
template="#createURI('processingDirective')#/cfprocessingdirective_preservecase.cfm",
url: {
default: true
}
);
expect(result.fileContent).toBeWithCase('{"CAMELCASE":"default"}');
});
});
}

private string function createURI(string calledName){
var baseURI="/test/#listLast(getDirectoryFromPath(getCurrentTemplatePath()),"\/")#/";
return baseURI&""&calledName;
}

private function isWindows(){
return (server.os.name contains "windows");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<cfprocessingdirective pageencoding="UTF-8">
<cfoutput>Encoding set to UTF-8</cfoutput>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<cfscript>
param name="url.default" value="false";
param name="url.preserve" value="true";
if (url.default){
st = {
camelCase: "default"
};
echo( st.toJson() );
} else if (url.preserve) {
processingDirective preserveCase=true {
st = {
camelCase: true
};
echo(st.toJson());
};
} else {
processingDirective preserveCase=false {
st = {
camelCase: false
};
echo(st.toJson());
};
}
</cfscript>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!--- this file uses LF line endings --->
<cfprocessingdirective suppresswhitespace="yes">
<cfoutput>
Line1
Line2
Line3
</cfoutput>
</cfprocessingdirective>

0 comments on commit 8f2ba4a

Please sign in to comment.