Copy link to clipboard
Copied
Why does this not work for the User Agent empty string?
<cfif REFindNoCase("^$", CGI.HTTP_USER_AGENT)>
<cfoutput>
"#CGI.HTTP_USER_AGENT#"
</cfoutput>
</cfif>
For obvious reasons this works as an alternative.
<cfif ! len(CGI.HTTP_USER_AGENT)>
<cfoutput>
"#CGI.HTTP_USER_AGENT#"
</cfoutput>
</cfif>
However, I'm not really interested in a workaround but the reason why the firt RegEx approach fails.
Testing conducted with FF Add-On "User Agent Switcher" I'm able to impersonate a browser that is void of a UA.
Other info:
Adobe ColdFusion 9.0.1
Server 2008 R2 64 bit
Testing code from within application.cfm
Copy link to clipboard
Copied
I would use "^.+" instead of "^$"
Copy link to clipboard
Copied
"^.+" should be the same as ".{1,}" which will match any single character that is not a line break character between one and unlimited times (greedy).
That also would essentially match just about anything which makes it very useless for matching since it would definitely pollute with false positives. Thanks for the assist though.