-
Notifications
You must be signed in to change notification settings - Fork 1.9k
StringUtils.abbreviate(String, String, int) contract violations #1572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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... |
Add 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.