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

#2283 Escape special characters in subject #2284

Merged
merged 3 commits into from May 23, 2023

Conversation

Au6ojlut
Copy link
Contributor

For example, in case of new line in subject the report schema is broken and all the report starts look ugly.

We need to escape characters before the line length computing.

Proposed changes

Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request.
If it fixes a bug or resolves a feature request, be sure to link to that issue.

Checklist

  • Checkstyle and unit tests are passed locally with my changes by running gradlew check chrome_headless firefox_headless command
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

For example, in case of new line in subject the report schema is broken and all the report starts look ugly.

We need to escape characters before the line length computing.
case '\n' -> builder.append("\\n");
case '\f' -> builder.append("\\f");
case '\b' -> builder.append("\\b");
default -> builder.append(symbol);
Copy link
Member

Choose a reason for hiding this comment

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

@Au6ojlut Maybe we should also escape all invisible characters below 32 (space)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, I'll fix it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

while (!stack.isEmpty() && stack.peekFirst().getEndTime() <= event.getStartTime())
var eventWithEscapedSubject = new LogEventWithNestingLevel.SimpleLogEvent(
event.getElement(),
escape(event.getSubject()),
Copy link
Member

Choose a reason for hiding this comment

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

At a first glance, the good moment to escape characters is not the construction of SimpleLogEvent, but when we render SimpleLogEvent. In other words, when we generate the resulting report. Then we could escape all fields, not only subject.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But we need to know the max size of a cell of the report table. If the calculation was made before the escape was applied then the final max size may be incorrect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since element and subject are just strings, I believe, that they are the only place where special characters can appear. So, it's enough to escape them, not all the report line/row.

But, I also didn't find a case when the element could contain some special characters (only some synthetic example), that's why I left it as is, but it can be easily fixed.

@asolntsev asolntsev added this to the 6.15.0 milestone May 14, 2023
@sonarcloud
Copy link

sonarcloud bot commented May 15, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@Au6ojlut Au6ojlut requested a review from asolntsev May 15, 2023 05:37
@asolntsev asolntsev self-assigned this May 18, 2023
@asolntsev asolntsev merged commit 197695d into selenide:main May 23, 2023
11 of 12 checks passed
@asolntsev asolntsev linked an issue May 28, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Escape special characters in SimpleReport **Subject section only**
2 participants