Util.js trim doesn't do what it says.

Bug #1028544 reported by Joseph
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Evergreen
Won't Fix
Undecided
Unassigned

Bug Description

The Javascript function trim()'s regex expression found in Util.js doesn't actually strip all trailing whitespace from the string given.

/^\s*(.+)?\s*$/

It looks like one of the ending spaces is removed, not all.

Tested in: Chromium 18.0.1025.168, Firefox 14.0.0.1
Evergreen Version: Head

Revision history for this message
Joseph (joehms22) wrote :
tags: added: pullrequest
Revision history for this message
Thomas Berezansky (tsbere) wrote :

Would

return s.replace(/^\s*.*?\s*$/,"$1");

be a better choice?

Revision history for this message
Joseph (joehms22) wrote :

I still get blank space at the end of that one:

s.replace(/^\s*(.*)?\s*$/,"$1");

Revision history for this message
Joseph (joehms22) wrote :

An interesting discussion is here: http://blog.stevenlevithan.com/archives/faster-trim-javascript

Upon further investigation it looks like dojo also provides the same functionality under dojo.trim; falling back on to the browser's native String.trim if it has one.

Revision history for this message
Thomas Berezansky (tsbere) wrote :

Whoops, sorry, forgot the capture group. >_>

s.replace(/^\s*(.*?)\s*$/,"$1");

The ? after the * makes it non-greedy.

Revision history for this message
Joseph (joehms22) wrote :

I updated the branch to work with this function, and it indeed works when I test using the JS Scratchpad in Firefox.

Revision history for this message
Dan Scott (denials) wrote :

Hi Joseph:

Was there any reason you opted not to use dojo.trim()? I would generally prefer to lean on the framework to handle utility functions like this whenever possible, rather than on our own implementation.

Revision history for this message
Joseph (joehms22) wrote :

I wasn't entirely sure if there was a reson for having our own script over Dojo's or the native browser's, like an old xulrunner. If memory serves me right, there was only one file to even use that function, so I'll can just lob it off entirely if that works.

Changed in evergreen:
status: New → Confirmed
Revision history for this message
Ben Shum (bshum) wrote :

Might be something we can pull out of this?

Changed in evergreen:
milestone: none → 2.4.0-rc
Ben Shum (bshum)
Changed in evergreen:
milestone: 2.4.0-rc → none
Revision history for this message
Kathy Lussier (klussier) wrote :

Removing pullrequest tag on this one for now.

tags: removed: pullrequest
no longer affects: evergreen/2.4
Changed in evergreen:
status: Confirmed → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.