You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "ThrawnCA (via GitHub)" <gi...@apache.org> on 2025/11/14 23:33:55 UTC

[PR] 'abbreviate' contract violations [commons-lang]

ThrawnCA opened a new pull request, #1490:
URL: https://github.com/apache/commons-lang/pull/1490

   I have added unit tests showing incorrect behaviour of `StringUtils.abbreviate` on short strings (between `abbrevMarker.length + 1` and `abbrevMarker.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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] 'abbreviate' contract violations [commons-lang]

Posted by "ThrawnCA (via GitHub)" <gi...@apache.org>.
ThrawnCA commented on PR #1490:
URL: https://github.com/apache/commons-lang/pull/1490#issuecomment-3758451097

   Additionally, if `abbrevMarker` is `null`, then the `maxWidth` is not applied.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] 'abbreviate' contract violations [commons-lang]

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #1490:
URL: https://github.com/apache/commons-lang/pull/1490#issuecomment-3589296768

   The failing test:
   ```java
           // abbreviating a shorter string allows maxWidth < 7
           assertEquals("...efg", StringUtils.abbreviate("abcdefg", 5, 6));
   ```
   looks like a bug indeed.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] 'abbreviate' contract violations [commons-lang]

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory merged PR #1490:
URL: https://github.com/apache/commons-lang/pull/1490


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] StringUtils.abbreviate(String, String, int) contract violations [commons-lang]

Posted by "ThrawnCA (via GitHub)" <gi...@apache.org>.
ThrawnCA commented on PR #1490:
URL: https://github.com/apache/commons-lang/pull/1490#issuecomment-3761890384

   I don't see a button to reopen it, but I can recreate it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] StringUtils.abbreviate(String, String, int) contract violations [commons-lang]

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #1490:
URL: https://github.com/apache/commons-lang/pull/1490#issuecomment-3761652201

   Hello @ThrawnCA 
   I accidentally clicked to merge instead of running the tests in the PR, which caused the build to fail with test failures. I had to revert this commit but I can't reopen the PR. Please reopen this PR.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] 'abbreviate' contract violations [commons-lang]

Posted by "TharinduSilva2019774 (via GitHub)" <gi...@apache.org>.
TharinduSilva2019774 commented on PR #1490:
URL: https://github.com/apache/commons-lang/pull/1490#issuecomment-3539549966

   Can you assign me for this issue?
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] 'abbreviate' contract violations [commons-lang]

Posted by "ThrawnCA (via GitHub)" <gi...@apache.org>.
ThrawnCA commented on PR #1490:
URL: https://github.com/apache/commons-lang/pull/1490#issuecomment-3759694161

   I think the original bug arises from the logic that shifts the offset when it's close to the end:
   
           if (strLen - offset < maxWidth - abbrevMarkerLength) {
               offset = strLen - (maxWidth - abbrevMarkerLength);
           }
   
   This can result in the offset being moved left far enough that the code then decides the best option is to keep the start unchanged and just truncate the end - but the truncated part might include the actual requested offset character.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] StringUtils.abbreviate(String, String, int) contract violations [commons-lang]

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #1490:
URL: https://github.com/apache/commons-lang/pull/1490#issuecomment-3762157725

   I am sorry about the extra work 🤦 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] 'abbreviate' contract violations [commons-lang]

Posted by "ThrawnCA (via GitHub)" <gi...@apache.org>.
ThrawnCA commented on PR #1490:
URL: https://github.com/apache/commons-lang/pull/1490#issuecomment-3544114569

   I'm unsure what's the best approach to fixing this. Should the documentation be updated to reflect the fact that for short strings, the offset marker might not be present in the result? Should the logic be changed so that the offset marker _is_ present, and if so, what is the most efficient way?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org