Skip to content
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

CompactFormatter precision and surrogate pairs #528

Closed
jmehrens opened this issue Feb 18, 2021 · 1 comment
Closed

CompactFormatter precision and surrogate pairs #528

jmehrens opened this issue Feb 18, 2021 · 1 comment
Assignees

Comments

@jmehrens
Copy link
Contributor

jmehrens commented Feb 18, 2021

Working on improving the code coverage for the CompactFormatter I noticed that the logic for handling precision can bisect a supplementary character.

The faulty code is here:
https://github.com/eclipse-ee4j/mail/blob/226d2d6f1db283042537fa9a30dfab798649fea2/mail/src/main/java/com/sun/mail/util/logging/CompactFormatter.java#L812

In its current form, the code is just dead code that could produce a garbage character. The good news is that java.util.Formatter doesn't handle supplementary characters either. See: java.util.Fomatter precision and surrogate pairs. This means that for all argument indexes precision will bisect in the same manor. Since the default format is using CompactFormatter$Alternate with a precision, supplementary characters should be handled correctly.

Need to write up tests to ensure that all CompactFormatter$Alternate parameters don't bisect supplementary characters.
In general the change is roughly:

  • Initial fence needs to be determined by counting code points.
  • Change the if to less than (or less than equal)
  • The substring should be incremented to the right instead of the left.
  • The fence shouldn't change because even though the string is larger it didn't take away any code points from the right side.
  • The right side string needs all of the same checking for supplementary characters the end of string.
  • Need to deal with not moving if the next char isn't the low surrogate.
  • Add tests for all of the possible bounds issues and edge cases.
  • Update JavaDocs to talk about precision is in code points.
@jmehrens jmehrens self-assigned this Feb 18, 2021
jmehrens added a commit to jmehrens/mail that referenced this issue Mar 27, 2021
Signed-off-by: jmehrens <jason_mehrens@hotmail.com>
jmehrens added a commit to jmehrens/mail that referenced this issue Mar 29, 2021
Signed-off-by: jmehrens <jason_mehrens@hotmail.com>
(cherry picked from commit 16d423d)
jmehrens added a commit to jmehrens/mail that referenced this issue Mar 29, 2021
Signed-off-by: jmehrens <jason_mehrens@hotmail.com>
lukasj pushed a commit that referenced this issue Apr 7, 2021
(cherry picked from commit 16d423d)

Signed-off-by: jmehrens <jason_mehrens@hotmail.com>
lukasj pushed a commit that referenced this issue Apr 7, 2021
Signed-off-by: jmehrens <jason_mehrens@hotmail.com>
@jmehrens
Copy link
Contributor Author

jmehrens commented Apr 7, 2021

Committed to 2.0.2-SNAPSHOT and 1.6.7-SNAPSHOT

@jmehrens jmehrens closed this as completed Apr 7, 2021
bvfalcon pushed a commit to bvfalcon/jakarta-mail that referenced this issue Aug 8, 2022
…ee#543)

Signed-off-by: jmehrens <jason_mehrens@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant