CF HTML5 Validation Gotcha

I spent some time scratching my head over this one and thought I’d share.

<cfset userAgent = trim(listGetAt(CGI.HTTP_USER_AGENT, 2, ';'))> <!--- This only works for IE --->
<cfset outtaDate = 'MSIE 8.0, MSIE 7.0b, MSIE 7.0, MSIE 6.1, MSIE 6.01, MSIE 6.0b, MSIE 6.0'> <!--- List all the versions of IE that are out of date --->
<cfif ListFindNoCase(outtaDate, userAgent, ',') NEQ 0> <!--- We're not gonna bump em from the site, but we will display a warning to those visitors using the older versions of IE --->
<div class="outtaDate">You are using an out of date version of Internet Explorer and this site <b>WILL NOT</b> display correctly. If you are using Windows Vista or Windows 7, please use Windows Update and upgrade to Internet Explorer 9 or newer. If you are using Windows XP and earlier which cannot upgrade to Internet Explorer 9, please download the latest version of <a href="" target="_blank">Firefox</a>, <a href="" target="_blank">Chrome</a>, <a href="" target="_blank">Opera</a> or <a href="" target="_blank">Safari</a> to see this site correctly.</div>

I’m using this code to identify older versions of IE that don’t support CSS3 and/or HTML5. Maybe I should be identifying browsers a better way, but the problem here lies within the listGetAt on line 1.

This code will trip up the W3C Markup Validation Service marking your code invalid with one of ColdFusion’s styles from an error… ColdFusion’s pumping out an error to the service… even though the running site won’t pump out an error at all.

Here is ColdFusion’s exception error to the W3C service:

In function ListGetAt(list, index [, delimiters]), the value of index, 2, is not a valid as the first argument (this list has 1 elements).&nbsp;Valid indexes are in the range 1 through the number of elements in the list.

I’m sure this isn’t a big deal since most people aren’t identifying browsers with their code or even coding in HTML5 for that matter, let alone valid HTML5 to use the W3C service (hopefully it’s more than I think).

Either way, I don’t know why the validator service is getting that error, having tested the code on virtually every browser without any problems (old and current alike). And I can’t really tell whether the problem is with CF or the W3C’s tool, but it’s not having any sort of effect on the live code, which is always a good thing.


  1. Timothy Leach says:

    The validator is probably passing a unique user agent,identifying itself as a bot, maybe try a CGI dump that gets emailed to yourself,or written to a log, and run the validator against it to see what that value is. Meanwhile, try checking the length of the list before getting the second value, or listappend a dummy value to ensure it’s always at least 2 items.

  2. Per Djurner says:

    The W3C’s user agent is something like “W3C_Validator/xx.xxxx” so you need to account for that in the code (no “;” character in there).

Leave a Reply

Your email address will not be published. Required fields are marked *