Skip to content

Instantly share code, notes, and snippets.

@bennadel
Created September 16, 2021 10:27
Show Gist options
  • Save bennadel/615e5fd3d8adb470a2a69be94356ce80 to your computer and use it in GitHub Desktop.
Save bennadel/615e5fd3d8adb470a2a69be94356ce80 to your computer and use it in GitHub Desktop.
Yahoo! Mail Does Not Render Anchor Tags With Encoded HREF Attributes
<h1>
You've been invited to a project
</h1>
<p>
Ben Nadel has invited you to join
<a href="https&#x3a;&#x2f;&#x2f;projects.invisionapp.com&#x2f;path&#x2f;to&#x2f;project&#x23;&#x2f;spa&#x2f;path">My Awesome Project</a>,
an InVision project.
</p>
<cfscript>
// Setup data to be used in email-template rendering.
project = {
owner: "Ben Nadel",
name: "My Awesome Project",
url: "https://projects.invisionapp.com/path/to/project##/spa/path"
};
</cfscript>
<cfoutput>
<h1>
You've been invited to a project
</h1>
<p>
#encodeForHtml( project.owner )# has invited you to join
<a href="#encodeForHtmlAttribute( project.url )#">#encodeForHtml( project.name )#</a>,
an InVision project.
</p>
</cfoutput>
<h1>
You've been invited to a project
</h1>
<p>
Ben Nadel has invited you to join
<a href="https://projects.invisionapp.com&#x2f;path&#x2f;to&#x2f;project&#x23;&#x2f;spa&#x2f;path">My Awesome Project</a>,
an InVision project.
</p>
<cfscript>
// Setup data to be used in email-template rendering.
project = {
owner: "Ben Nadel",
name: "My Awesome Project",
url: "https://projects.invisionapp.com/path/to/project##/spa/path"
};
</cfscript>
<cfoutput>
<h1>
You've been invited to a project
</h1>
<p>
#encodeForHtml( project.owner )# has invited you to join
<a href="#encodeForHrefAttribute( project.url )#">#encodeForHtml( project.name )#</a>,
an InVision project.
</p>
</cfoutput>
<cfscript>
/**
* I encoded the given value for use in an HREF attribute. This is designed to reduce
* the amount of encoded characters so as to make the resultant value a little more
* mail-client friendly.
*/
public string function encodeForHrefAttribute( required string value ) {
var encodedValue = encodeForHtmlAttribute( value );
// The encodeForHtmlAttribute() function will encode just about any non-alpha-
// numeric character. Which, in most cases is completely fine. But, for Yahoo!
// Mail, we need to back that encoding off just a bit, unencoding the protocol
// suffix.
var unencodedSuffix = "://";
var encodedSuffix = encodeForHtmlAttribute( unencodedSuffix );
// Replace the encoded protocol with the unencoded version.
var fixedValue = encodedValue.reReplaceNoCase(
"^([a-z0-9]+)#encodedSuffix#",
"\1#unencodedSuffix#"
);
return( fixedValue );
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment