Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Empty User Agent string checking with RegEx fails

Guest
Aug 12, 2013 Aug 12, 2013

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

742
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 12, 2013 Aug 12, 2013

I would use "^.+" instead of "^$"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 12, 2013 Aug 12, 2013
LATEST

"^.+" 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources