Reviewers: jlabanca,
Please review this at http://gwt-code-reviews.appspot.com/126821 Affected files: user/super/com/google/gwt/emul/java/lang/String.java user/test/com/google/gwt/emultest/java/lang/StringTest.java Index: user/super/com/google/gwt/emul/java/lang/String.java =================================================================== --- user/super/com/google/gwt/emul/java/lang/String.java (revision 7347) +++ user/super/com/google/gwt/emul/java/lang/String.java (working copy) @@ -23,7 +23,6 @@ package java.lang; import com.google.gwt.core.client.JavaScriptObject; -import com.google.gwt.user.client.Window; import java.io.Serializable; import java.util.Comparator; @@ -658,11 +657,11 @@ // progress by intention var lastTrail = null; // We do the split manually to avoid Javascript incompatibility - while(true) { + while (true) { // None of the information in the match returned are useful as we have no // subgroup handling var matchObj = compiled.exec(trail); - if( matchObj == null || trail == "" || + if (matchObj == null || trail == "" || (count == (maxMatch - 1) && maxMatch > 0)) { out[count] = trail; break; @@ -680,8 +679,10 @@ count++; } } - // all blank delimiters at the end are supposed to disappear if maxMatch == 0 - if (maxMatch == 0) { + // all blank delimiters at the end are supposed to disappear if maxMatch == 0; + // however, if the input string is empty, the output should consist of a + // single empty string + if (maxMatch == 0 && this.length > 0) { var lastNonEmpty = out.length; while (lastNonEmpty > 0 && out[lastNonEmpty - 1] == "") { --lastNonEmpty; @@ -742,7 +743,7 @@ }-*/; public native String trim() /*-{ - if(this.length == 0 || (this[0] > '\u0020' && this[this.length-1] > '\u0020')) { + if (this.length == 0 || (this[0] > '\u0020' && this[this.length-1] > '\u0020')) { return this; } var r1 = this.replace(/^(\s*)/, ''); Index: user/test/com/google/gwt/emultest/java/lang/StringTest.java =================================================================== --- user/test/com/google/gwt/emultest/java/lang/StringTest.java (revision 7346) +++ user/test/com/google/gwt/emultest/java/lang/StringTest.java (working copy) @@ -429,6 +429,14 @@ 0)); // issue 2742 compareList("issue2742", new String[] {}, hideFromCompiler("/").split("/", 0)); + + // Splitting an empty string should result in an array containing a single + // empty string. + String[] s = "".split(","); + assertTrue(s != null); + assertTrue(s.length == 1); + assertTrue(s[0] != null); + assertTrue(s[0].length() == 0); } public void testStartsWith() { -- http://groups.google.com/group/Google-Web-Toolkit-Contributors
