Skip to content

Replace non-printable characters in display names #4813

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sbrannen
Copy link
Member

@sbrannen sbrannen commented Aug 6, 2025

Prior to this commit, display names were "sanitized" before they were printed via the ConsoleLauncher (#1713), and text-based arguments in display names for parameterized tests were quoted and escaped (#4716). However, there was still the chance that display names could contain control characters such as CR or LF.

To address that, this commit introduces support for automatically replacing non-printable characters in any display name passed to one of the constructors for AbstractTestDescriptor. Doing so automatically covers all display names in Jupiter, @SuiteDisplayName, and any other test engines that subclass AbstractTestDescriptor, which should cover most common use cases.

Specifically, the following replacements are performed.

  • \r -> <CR>
  • \n -> <LF>
  • ISO control character -> � (Unicode replacement character)

This commit also removes the special handling of ISO control characters from QuoteUtils, since this is now handled within AbstractTestDescriptor.

@marcphilipp marcphilipp requested a review from sormuras August 15, 2025 10:52
Prior to this commit, display names were "sanitized" before they were
printed via the ConsoleLauncher (junit-team#1713), and text-based arguments in
display names for parameterized tests were quoted and escaped (junit-team#4716).
However, there was still the chance that display names could contain
control characters such as CR or LF.

To address that, this commit introduces support for automatically
replacing non-printable characters in any display name passed to one of
the constructors for AbstractTestDescriptor. Doing so automatically
covers all display names in JUnit Jupiter, @⁠SuiteDisplayName, and any
other test engines that subclass AbstractTestDescriptor, which should
cover most common use cases.

Specifically, the following replacements are performed.

- \r -> <CR>
- \n -> <LF>
- ISO control character -> � (Unicode replacement character)

This commit also removes the special handling of ISO control characters
from QuoteUtils, since this is now handled in AbstractTestDescriptor.

See junit-team#1713
See junit-team#4716
Closes junit-team#4714
@sbrannen sbrannen force-pushed the issues/4714-replace-non-printable-characters-in-display-names branch from 87eb2f6 to 3bee7af Compare August 15, 2025 12:51
@sbrannen
Copy link
Member Author

@sormuras, I already used Japanese text in the test, but I just added (and force pushed) Thai text in the test.

https://github.com/junit-team/junit-framework/pull/4813/files#diff-56cff8e2d4043d4b5b09a824f4b3073c6fe7ed66ecbd7af98a5025f08489bbfdR172-R194

And I had already used an emoji.

So I think we are adequately testing support for multi-byte characters.

@sbrannen
Copy link
Member Author

Running AbstractTestDescriptorTests.specialCharactersInDisplayNamesAreEscaped(String, String) in Eclipse IDE now results in the following output in the UI.

AbstractTestDescriptorTests

Copy link
Member

@sormuras sormuras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Escape implementation based on char and associated tests look good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace non-printable characters in display names
3 participants