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

URL encoding issue in "All Failed Tests" links with square brackets #662

Closed
ahadalioglu opened this issue Nov 14, 2024 · 7 comments · Fixed by #668
Closed

URL encoding issue in "All Failed Tests" links with square brackets #662

ahadalioglu opened this issue Nov 14, 2024 · 7 comments · Fixed by #668

Comments

@ahadalioglu
Copy link
Contributor

ahadalioglu commented Nov 14, 2024

Jenkins and plugins versions report

Environment
Jenkins: 2.479.1
OS: Linux - 6.1.112-124.190.amzn2023.x86_64
Java: 17.0.13 - Amazon.com Inc. (OpenJDK 64-Bit Server VM)
---
<plugins_omitted>
junit:1307.vdd5b_2646279e
<plugins_omitted>

What Operating System are you using (both controller, and any agents involved in the problem)?

Thank you to everyone who worked on resolving issue #659. I can confirm that the "All Tests" link now functions as expected, with all associated links working correctly.

However, links for individual failed test reports (All Failed Tests) are still encountering the original issue: square brackets in the URLs are not being replaced with percent-encodings, which still results in link failures. I've attached a screenshot for additional context:
Error Screenshot

Thank you for your continued efforts on this.

Reproduction steps

Access test results/reports via link:
https://<jenkins_url>/job/<job_name>/<build_number>/testReport/(root)/[AUTOMATION]

Expected Results

Convert link to this:
https://<jenkins_url>/job/<job_name>/<build_number>/testReport/(root)/%5BAUTOMATION%5D

Actual Results

HTTP ERROR 400 Illegal Path Character

URI: /badURI
STATUS: 400
MESSAGE: Illegal Path Character

Powered by Jetty:// 12.0.13

Anything else?

No response

Are you interested in contributing a fix?

No response

@ahadalioglu ahadalioglu changed the title URL encoding issue in "All Failed Test" links with square brackets URL encoding issue in "All Failed Tests" links with square brackets Nov 14, 2024
@alecharp
Copy link
Member

I tried to reproduce the problem here with a simple Maven project, unit JUnit 5 and parameterized tests. Those create tests with ( and [.
It seems that it's not the correct way to reproduce your problem as the link to the failing tests is using _ in place of the brackets.
As the screenshot is not accessible, I cannot confirm what you are facing.

I do believe that the problem is in my setup, not being able to create tests correctly, creating this problem. Could you please explicit how those tests are creating? Maybe you have an example I could follow.

@ahadalioglu
Copy link
Contributor Author

Thank you for your response.
A picture is not necessary; let me explain the issue in detail:

All Tests consists of multiple categories, and all failed tests can also be accessed from All Tests. When navigating through All Tests, all links work without any issues. However, when I try to use direct links from All Failed Tests, the brackets in the category names within the URL are not encoded correctly. Here's a detailed example:

In All Tests, the category [AUTOMATION] Category 1 has the following encoded link when accessed via (root): https://<jenkins_url>/job/<job_name>/<build_number>/testReport/(root)/%5BAUTOMATION%5D%20Category%201/

On the other hand, when accessed via All Failed Tests, the subcategory is displayed as [AUTOMATION] Category 1.[SubCategory] Result - #1.1, however, the corresponding encoded link is: https://<jenkins_url>/job/<job_name>/<build_number>/testReport/(root)/[AUTOMATION]%20Category%201/_SubCategory__Result____1_1

As you can see, the links from All Failed Tests are handled differently. The category is encoded one way, while the subcategory is encoded another way.

I hope this explanation provides a clearer view of the problem.

@timja
Copy link
Member

timja commented Nov 19, 2024

It would be easier to reproduce if you could provide a simple junit.xml file which matches your setup

@ahadalioglu
Copy link
Contributor Author

ahadalioglu commented Nov 20, 2024

Unfortunately, I cannot provide a simple file, but I would like to suggest a possible solution:

After thoroughly reviewing last two merged commits that introduced new fix releases, I noticed that only the "All Tests" sections were updated (all instances of ${p.safeName} were replaced with encodedRelativePath), while no changes were made to the "All Failed Tests" sections. This leads me to suspect that the safeName and getRelativePathFrom values might be processed differently in these cases.

Could you please check if handling all instances of ${f.getRelativePathFrom(it)} in the same way as ${p.safeName} ensures proper URL encoding for the "All Failed Tests" section as well?

For example, replacing:
<a href="${f.getRelativePathFrom(it)}"><st:out value="${f.fullName}"/></a>

With:

<j:invokeStatic var="encodedRelativePath" className="hudson.Util" method="rawEncode">
  <j:arg value="${f.getRelativePathFrom(it)}" />
</j:invokeStatic>
<a href="${encodedRelativePath}"><st:out value="${f.fullName}"/></a>

This might address the inconsistency.

Thank you for your consideration in advance!

@ahadalioglu
Copy link
Contributor Author

Hi again,

I understand everyone is quite busy, or perhaps my earlier message wasn't entirely clear. To help, I forked the repo and implemented the changes I proposed.

Could you kindly review my branch and let me know if there's anything that needs adjustment?

https://github.com/ahadalioglu/junit-plugin/tree/url-encode-fix-for-all-failed-tests

Thanks in advance

@timja
Copy link
Member

timja commented Nov 29, 2024

Could you please create a pull request

@ahadalioglu
Copy link
Contributor Author

ahadalioglu commented Dec 1, 2024

I have created PR, please kindly review at your convenience and let me know if there is anything missing.
#664

UPDATE: pipeline failed, it seems it's missing tests:
No test report files were found. Configuration error?

Need some help, please...

These are only changes we need:
master...ahadalioglu:junit-plugin:url-encode-fix-for-all-failed-tests

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

Successfully merging a pull request may close this issue.

3 participants