StringUtils.abbreviate(String, String, int) contract violations#1572
StringUtils.abbreviate(String, String, int) contract violations#1572ThrawnCA wants to merge 5 commits intoapache:masterfrom
Conversation
- treat null marker as empty string - ensure offset and maxWidth are applied as usual (simple 'substring' won't cut it)
- Abbreviated strings should always retain the 'offset' character
…abbreviate-short-strings-errors
| assertAbbreviateWithOffset("...ijklmno", 15, 10); | ||
| assertAbbreviateWithOffset("...ijklmno", 16, 10); | ||
| assertAbbreviateWithOffset("...ijklmno", Integer.MAX_VALUE, 10); | ||
|
|
There was a problem hiding this comment.
No need for extra blank lines, you have // comments.
|
I can see some possible paths to fixing this, but more clarity is needed on the desired behaviour. In cases such as
If 1) is preferred, then the existing unit test: is incorrect. It should instead abbreviate to On the other hand, if 2) is preferred, then the existing unit test: is incorrect. This case should instead abbreviate to Or, if both behaviours are acceptable, then the unit tests are too strict. The decision on this will inform what direction the fix for short strings will take. |
|
Hello @ThrawnCA Thank you for your report. The new (failing) test cases look correct to me. I'll wait for your changes... |
As mentioned above, more discussion is needed about the best path to fixing this. I'm pretty sure that any way I can do it would break at least one existing unit test, because the tests are stricter than the method contract. |
Added unit tests demonstrating incorrect behaviour of
StringUtils.abbreviateon short strings (betweenabbrevMarker.length + 1andabbrevMarker.length * 2).The documentation states that the offset character will always appear somewhere in the result, but when an offset is applied to a short string, it may not be.
Thanks for your contribution to Apache Commons! Your help is appreciated!
Before you push a pull request, review this list:
mvn; that'smvnon the command line by itself.