Skip to main content
Known Participant
January 22, 2011
Answered

#...# expression leaves superflous space behind for the first #

  • January 22, 2011
  • 1 reply
  • 507 views

hi there

I run CF 9.01 and have a nasty white space problem:

I populate a form field like this:

---

... value="#application.utils.FormatTS(now())#" ...

---

This leaves behind in the source code generated the followng:

----

value=" 2011-01-22 03:34:03"

---

The empty space later generates a problem. I have observed this bug throughout all versions of CF. One can avoid this in all situation where one can concatenate strings like in "some test" & application.utils.FormatTS() ... this will not geneate the empty space.

CF's IsDate () returns NO if the space is there ...LSIsDate () returns YES ... inconsistent behavior IMHO.

BTW: The function FormatTS () does NOT generate the leading space. It is the way how CF generates the code

BTW: I know that I can get rid of the space with trim() ... however, it's a mess to be forced to do so in ALL processing of such constructs ...

Any remedy known for this? Or any reason WHY CF does it like this? How can I seduce it not to generate suc code?

Thanks

Martin

    This topic has been closed for replies.
    Correct answer -__cfSearching__-

    BTW: The function FormatTS () does NOT generate the leading

    space. It is the way how CF generates the code

    Are you positive? Because that certainly is the most likely cause. Check the cffunction and make sure you have set output="false".

    1 reply

    -__cfSearching__-Correct answer
    Inspiring
    January 22, 2011

    BTW: The function FormatTS () does NOT generate the leading

    space. It is the way how CF generates the code

    Are you positive? Because that certainly is the most likely cause. Check the cffunction and make sure you have set output="false".

    tinu8805Author
    Known Participant
    January 22, 2011

    Yes, I am sure

    This is the cfc wth the method

    ---

    <cfcomponent output="false">


       <cffunction name="FormatTS" access="public" returntype="string" hint="Returns a timestamp formatted as yyyy-mm-dd hh:mm:ss">

          <cfargument name="Timestamp"           type="any"    required="yes">

          <cfargument name="Date_Time_Separator" type="string" required="no" default=" ">

          <cfreturn (arguments.Timestamp gt "" ? DateFormat (arguments.Timestamp, "yyyy-mm-dd") & arguments.Date_Time_Separator & TimeFormat (arguments.Timestamp, "HH:mm:ss") : "")>

       </cffunction>

    ---

    Howerver, I see that I can also set output="false" in the method. I was not aware that this MUST be done ... cause obviously, when doing so, the superfluos space does disappear .... so, your comment helped. Strange, I don't understand the difference right now .. anyway.

    Inspiring
    January 22, 2011

    You need to specify output="false" on the function too.

    (Update: I responded via email before I saw your edit.)

    The documentation says it controls whether "the entire function body is processed as if it were in a cfoutput tag...". (and functions do not inherit the setting of the parent cfcomponent tag). I cannot say I always understand how certain code ends up creating the whitespace in the first place. But as it is easily fixed, I never spent that much time investigating.

    Message was edited by: -==cfSearching==-