Skip to content

Instantly share code, notes, and snippets.

@JamoCA
Last active October 31, 2022 17:39
Show Gist options
  • Save JamoCA/a56dfd74aa4ae9dad57747f516d6196a to your computer and use it in GitHub Desktop.
Save JamoCA/a56dfd74aa4ae9dad57747f516d6196a to your computer and use it in GitHub Desktop.
CFHTMLHead content is no longer added after a reset using CFContent.
<!--- 20221028 Starting with CF2021, CFHTMLHead text is no longer added after a reset using CFContent. (Undocumented)
Tweet: https://twitter.com/gamesover/status/1586142456491298816
Gist: https://gist.github.com/JamoCA/a56dfd74aa4ae9dad57747f516d6196a
--->
<cfhtmlhead text="<meta name=""info"" content=""I should be in the HEAD section."">">
<cfcontent type="text/html; charset=UTF-8" reset="true">
<p>View Source (Check for existence of metatag above this line.)</p>
<p>In Adobe ColdFusion 9-2018 & Lucee, the CFHTMLHead text is correctly added. CF2021 fails to add anything after cfcontent.</p>
<cfabort>
<!--- 20221028 Using a UDF to get+clean the ColdFusion headerBuffer before CF2021 automatically clears it during CFContent.
Tweet: https://twitter.com/gamesover/status/1586142456491298816
Gist: https://gist.github.com/JamoCA/a56dfd74aa4ae9dad57747f516d6196a
--->
<cfscript>
// 20221028 Inspiration from https://pastebin.com/f2560e44d (10/8/2009)
any function getCFHtmlHead(boolean clear=true) output=true hint="Retrieves (and optionally clears) the CFHTMLHead buffer" {
local.out = getPageContext().getOut();
while (getMetaData(local.out).getName() eq "coldfusion.runtime.NeoBodyContent") {
local.out = local.out.getEnclosingWriter();
}
local.field = local.out.getClass().getDeclaredField("appendHeaderBuffer");
local.field.setAccessible( true );
local.buffer = local.field.get(local.out);
local.output = (structkeyexists(local, "buffer")) ? local.buffer.toString() : "";
if (arguments.clear){
local.method = local.out.getClass().getDeclaredMethod('initHeaderBuffer', []);
local.method.setAccessible( true );
local.method.invoke(local.out, []);
}
return local.output;
}
</cfscript>
<cfhtmlhead text="<meta name=""info"" content=""I should be in the HEAD section."">">
<cfset headerContent = getCFHtmlHead()>
<cfcontent type="text/html; charset=UTF-8" reset="true">
<p>View Source (Check for existence of metatag above this line.)</p>
<p>In Adobe ColdFusion 9-2018 & Lucee, the CFHTMLHead text is correctly added. CF2021 fails to add anything after cfcontent.</p>
<cfif len(headerContent)>
<cfhtmlhead text="#headerContent#">
</cfif>
<cfabort>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment