Skip to content

Commit 636a248

Browse files
ris58hnhojpatrick
authored andcommitted
Add no-break space character handling to IsEqualCompressingWhiteSpace
1 parent e70007c commit 636a248

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

hamcrest/src/main/java/org/hamcrest/text/IsEqualCompressingWhiteSpace.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void describeTo(Description description) {
3939
}
4040

4141
public String stripSpaces(String toBeStripped) {
42-
return toBeStripped.replaceAll("\\s+", " ").trim();
42+
return toBeStripped.replaceAll("[\\p{Z}\\p{C}]+", " ").trim();
4343
}
4444

4545
/**

hamcrest/src/test/java/org/hamcrest/text/IsEqualCompressingWhiteSpaceTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,8 @@ public void testHasAReadableDescription() {
4141
assertDescription("a string equal to \" Hello World how\\n are we? \" compressing white space",
4242
matcher);
4343
}
44+
45+
public void testPassesIfWhitespacesContainsNoBreakSpace() {
46+
assertMatches(matcher, "Hello" + ((char)160) + "World how are we?");
47+
}
4448
}

0 commit comments

Comments
 (0)