Skip to content

Commit 2a52a06

Browse files
authored
Restore compatibility in whitespace detection (#4692)
`String.trim()` is now used consistently. See #3824 (comment) for details.
1 parent f8513cb commit 2a52a06

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

junit-jupiter-params/src/main/java/org/junit/jupiter/params/provider/CsvFileSource.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@
225225
* Controls whether leading and trailing whitespace characters of unquoted
226226
* CSV columns should be ignored.
227227
*
228+
* <p>Whitespace refers to characters with Unicode code points less than
229+
* or equal to {@code U+0020}, as defined by {@link String#trim()}.
230+
*
228231
* <p>Defaults to {@code true}.
229232
*
230233
* @since 5.8

junit-jupiter-params/src/main/java/org/junit/jupiter/params/provider/CsvReaderFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public String modify(long unusedStartingLineNumber, int unusedFieldIdx, boolean
165165
if (!quoted && field.isBlank()) {
166166
return NULL_MARKER;
167167
}
168-
String modifiedField = (!quoted && ignoreLeadingAndTrailingWhitespaces) ? field.strip() : field;
168+
String modifiedField = (!quoted && ignoreLeadingAndTrailingWhitespaces) ? field.trim() : field;
169169
if (nullValues.contains(modifiedField)) {
170170
return NULL_MARKER;
171171
}

junit-jupiter-params/src/main/java/org/junit/jupiter/params/provider/CsvSource.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@
286286
* Controls whether leading and trailing whitespace characters of unquoted
287287
* CSV columns should be ignored.
288288
*
289+
* <p>Whitespace refers to characters with Unicode code points less than
290+
* or equal to {@code U+0020}, as defined by {@link String#trim()}.
291+
*
289292
* <p>Defaults to {@code true}.
290293
*
291294
* @since 5.8

jupiter-tests/src/test/java/org/junit/jupiter/params/provider/CsvArgumentsProviderTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ void trimsTrailingSpaces() {
126126
assertThat(arguments).containsExactly(new Object[][] { { "1", "" }, { "2", "" }, { "3", "" }, { "4", "" } });
127127
}
128128

129+
@Test
130+
void trimsSpacesUsingStringTrim() {
131+
// \u0000 (null) removed by trim(), preserved by strip()
132+
// \u00A0 (non-breaking space) preserved by trim(), removed by strip()
133+
var annotation = csvSource().lines("\u0000foo,\u00A0bar", "\u0000' foo',\u00A0' bar'").build();
134+
135+
var arguments = provideArguments(annotation);
136+
137+
assertThat(arguments).containsExactly(array("foo", "\u00A0bar"), array(" foo", "\u00A0' bar'"));
138+
}
139+
129140
@Test
130141
void ignoresLeadingAndTrailingSpaces() {
131142
var annotation = csvSource().lines("1,a", "2, b", "3,c ", "4, d ") //

0 commit comments

Comments
 (0)