jenkinsci / junit-plugin

Allows JUnit-format test results to be published
https://plugins.jenkins.io/junit
MIT License
76 stars 337 forks source link

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

Open ahadalioglu opened 1 week ago

ahadalioglu commented 1 week ago

Jenkins and plugins versions report

Environment ```text 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) --- junit:1307.vdd5b_2646279e ```

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:///job///testReport/(root)/[AUTOMATION]

Expected Results

Convert link to this: https:///job///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

alecharp commented 1 week ago

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 commented 1 week ago

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 commented 1 week ago

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

ahadalioglu commented 1 week ago

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!