Commit 4a6a984
authored
StringUtils.abbreviate(String, String, int) contract violations (#1572)
* add unit tests showing mishandling of null abbrevMarker
* fix handling of null abbrevMarker
- treat null marker as empty string
- ensure offset and maxWidth are applied as usual (simple 'substring' won't cut it)
* add unit tests showing 'abbreviate' contract violations
- Abbreviated strings should always retain the 'offset' character
* remove surplus blank lines from tests
* fix StringUtils.abbreviate for short strings
Adjust logic so it doesn't overwrite the offset value and get confused about which character to preserve.
Instead, just return immediately if the offset is so close to the end that no ending abbrevMarker is possible.1 parent e23f953 commit 4a6a984
2 files changed
Lines changed: 8 additions & 9 deletions
File tree
- src
- main/java/org/apache/commons/lang3
- test/java/org/apache/commons/lang3
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
369 | 369 | | |
370 | 370 | | |
371 | 371 | | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
| 372 | + | |
| 373 | + | |
377 | 374 | | |
378 | 375 | | |
379 | 376 | | |
380 | 377 | | |
381 | 378 | | |
382 | 379 | | |
383 | 380 | | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
| 381 | + | |
388 | 382 | | |
389 | 383 | | |
390 | 384 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
| 105 | + | |
104 | 106 | | |
105 | 107 | | |
106 | 108 | | |
| |||
163 | 165 | | |
164 | 166 | | |
165 | 167 | | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
166 | 171 | | |
167 | 172 | | |
168 | 173 | | |
| |||
0 commit comments