Tuesday, January 14, 2014

Re: Differences between DevMode and Production mode related to trim()



On Monday, January 13, 2014 8:38:49 PM UTC+1, Jens wrote:
It does look like there is a real difference between Java's trim() and the following JavaScript:

  1. var r1 = this.replace(/^(\s*)/, '');
  2. var r2 = r1.replace(/\s*$/, '');

A JavaScript whitespace character can be:

  • A space character
  • A tab character
  • A carriage return character
  • A new line character
  • A vertical tab character
  • A form feed character
Our Strings are all filled with null characters ('\0')) due to our ancient C backend. trim() in Java works perfectly for this. But GWT's production/JavaScript trim() does not work. This leads to much of our app being broken due to comparison checks that worked in DevMode, not working in production.

Maybe worth a bug entry.

+1

The emulation should read:

    var r1 = this.replace(/^[\0- ]*/, '');
    var r2 = r1.replace(/[\0- ]*$/, '');
    return r2;

(either [\0- ]* or [\0- ]+)

That works in Chrome, but would have to be tested in all supported browsers.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment