Skip to content

Commit c14f5cb

Browse files
authored
Fix group references in String::matches (#10189)
Fixes #9572 by applying the change proposed by @morganga.
1 parent fcf9088 commit c14f5cb

File tree

6 files changed

+32
-29
lines changed

6 files changed

+32
-29
lines changed

dev/core/test/org/apache/commons/collections/collection/AbstractTestCollection.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ public void testUnsupportedAdd() {
591591
resetEmpty();
592592
try {
593593
collection.add(new Object());
594-
fail("Emtpy collection should not support add.");
594+
fail("Empty collection should not support add.");
595595
} catch (UnsupportedOperationException e) {
596596
// expected
597597
}
@@ -601,7 +601,7 @@ public void testUnsupportedAdd() {
601601

602602
try {
603603
collection.addAll(Arrays.asList(getFullElements()));
604-
fail("Emtpy collection should not support addAll.");
604+
fail("Empty collection should not support addAll.");
605605
} catch (UnsupportedOperationException e) {
606606
// expected
607607
}
@@ -929,12 +929,12 @@ public void testCollectionRemoveAll() {
929929
if (!isRemoveSupported()) return;
930930

931931
resetEmpty();
932-
assertTrue("Emtpy collection removeAll should return false for " +
932+
assertTrue("Empty collection removeAll should return false for " +
933933
"empty input",
934934
!collection.removeAll(Collections.EMPTY_SET));
935935
verify();
936936

937-
assertTrue("Emtpy collection removeAll should return false for " +
937+
assertTrue("Empty collection removeAll should return false for " +
938938
"nonempty input",
939939
!collection.removeAll(new ArrayList(collection)));
940940
verify();

user/super/com/google/gwt/emul/java/lang/String.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,9 +518,10 @@ public int length() {
518518
*
519519
* TODO(jat): properly handle Java regex syntax
520520
*/
521+
@SuppressWarnings("checkstyle:SpaceAfterColon")
521522
public boolean matches(String regex) {
522523
// We surround the regex with '^' and '$' because it must match the entire string.
523-
return new NativeRegExp("^(" + regex + ")$").test(this);
524+
return new NativeRegExp("^(?:" + regex + ")$").test(this);
524525
}
525526

526527
public int offsetByCodePoints(int index, int codePointOffset) {

user/test/com/google/gwt/emultest/java/lang/CharacterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ public void testIsSpace() {
337337
assertTrue(Character.isSpace('\n'));
338338
}
339339

340-
public void testIsWhitepace() {
340+
public void testIsWhitespace() {
341341
char[] separators = {
342342
'\u0020', // SPACE.
343343
'\u1680', // OGHAM SPACE MARK.

user/test/com/google/gwt/emultest/java/lang/StringTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,8 @@ public void testMatch() {
623623
assertFalse("11f.1", hideFromCompiler("ab").matches("|none"));
624624
assertFalse("11f.2", hideFromCompiler("anoneb").matches("|none"));
625625
assertTrue("12t", hideFromCompiler("none").matches("^|none$"));
626+
assertTrue("13t", hideFromCompiler("abccd").matches(".*(.)\\1.*"));
627+
assertFalse("13t", hideFromCompiler("abcd").matches(".*(.)\\1.*"));
626628
}
627629

628630
public void testNull() {

user/test/com/google/gwt/emultest/java/util/TestCollection.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ public void testUnsupportedAdd() {
411411
resetEmpty();
412412
try {
413413
collection.add(new Object());
414-
fail("Emtpy collection should not support add.");
414+
fail("Empty collection should not support add.");
415415
} catch (UnsupportedOperationException e) {
416416
// expected
417417
}
@@ -421,7 +421,7 @@ public void testUnsupportedAdd() {
421421

422422
try {
423423
collection.addAll(Arrays.asList(getFullElements()));
424-
fail("Emtpy collection should not support addAll.");
424+
fail("Empty collection should not support addAll.");
425425
} catch (UnsupportedOperationException e) {
426426
// expected
427427
}
@@ -712,12 +712,12 @@ public void testCollectionRemoveAll() {
712712

713713
resetEmpty();
714714
assertTrue(
715-
"Emtpy collection removeAll should return false for " + "empty input",
715+
"Empty collection removeAll should return false for " + "empty input",
716716
!collection.removeAll(Collections.EMPTY_SET));
717717
verify();
718718

719719
assertTrue(
720-
"Emtpy collection removeAll should return false for " + "nonempty input",
720+
"Empty collection removeAll should return false for " + "nonempty input",
721721
!collection.removeAll(new ArrayList(collection)));
722722
verify();
723723

user/test/com/google/gwt/emultest/java11/lang/StringTest.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,39 +33,39 @@ public void testIsBlank() {
3333
}
3434

3535
public void testStrip() {
36-
stripRightAsssertEquals("", "");
37-
stripRightAsssertEquals("", " ");
38-
stripRightAsssertEquals("x", " x ");
39-
stripRightAsssertEquals("x", "\u001cx\u001c");
40-
stripRightAsssertEquals("\u00a0x\u00a0", "\u00a0x\u00a0 ");
41-
stripRightAsssertEquals("\uffefx\u180e", "\uffefx\u180e ");
36+
stripRightAssertEquals("", "");
37+
stripRightAssertEquals("", " ");
38+
stripRightAssertEquals("x", " x ");
39+
stripRightAssertEquals("x", "\u001cx\u001c");
40+
stripRightAssertEquals("\u00a0x\u00a0", "\u00a0x\u00a0 ");
41+
stripRightAssertEquals("\uffefx\u180e", "\uffefx\u180e ");
4242
}
4343

4444
public void testStripLeading() {
45-
stripRightLeadingAsssertEquals("", "");
46-
stripRightLeadingAsssertEquals("", " ");
47-
stripRightLeadingAsssertEquals("x ", " x ");
48-
stripRightLeadingAsssertEquals("x\u001c", "\u001cx\u001c");
49-
stripRightLeadingAsssertEquals("\u00a0x\u00a0", "\u00a0x\u00a0");
45+
stripRightLeadingAssertEquals("", "");
46+
stripRightLeadingAssertEquals("", " ");
47+
stripRightLeadingAssertEquals("x ", " x ");
48+
stripRightLeadingAssertEquals("x\u001c", "\u001cx\u001c");
49+
stripRightLeadingAssertEquals("\u00a0x\u00a0", "\u00a0x\u00a0");
5050
}
5151

5252
public void testStripTrailing() {
53-
stripRightTrailingAsssertEquals("", "");
54-
stripRightTrailingAsssertEquals("", " ");
55-
stripRightTrailingAsssertEquals(" x", " x ");
56-
stripRightTrailingAsssertEquals("\u001cx", "\u001cx\u001c");
57-
stripRightTrailingAsssertEquals("\u00a0x\u00a0", "\u00a0x\u00a0 ");
53+
stripRightTrailingAssertEquals("", "");
54+
stripRightTrailingAssertEquals("", " ");
55+
stripRightTrailingAssertEquals(" x", " x ");
56+
stripRightTrailingAssertEquals("\u001cx", "\u001cx\u001c");
57+
stripRightTrailingAssertEquals("\u00a0x\u00a0", "\u00a0x\u00a0 ");
5858
}
5959

60-
private void stripRightAsssertEquals(String expected, String arg) {
60+
private void stripRightAssertEquals(String expected, String arg) {
6161
assertEquals(expected, hideFromCompiler(arg).strip());
6262
}
6363

64-
private void stripRightLeadingAsssertEquals(String expected, String arg) {
64+
private void stripRightLeadingAssertEquals(String expected, String arg) {
6565
assertEquals(expected, hideFromCompiler(arg).stripLeading());
6666
}
6767

68-
private void stripRightTrailingAsssertEquals(String expected, String arg) {
68+
private void stripRightTrailingAssertEquals(String expected, String arg) {
6969
assertEquals(expected, hideFromCompiler(arg).stripTrailing());
7070
}
7171

0 commit comments

Comments
 (0)