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

Brackets fix for all failed tests sections #667

Conversation

ahadalioglu
Copy link
Contributor

Testing done through Jenkins: https://ci.jenkins.io/job/Plugins/job/junit-plugin/job/PR-664/

After the fix implemented in PR #661, the "All Failed Tests" sections continued to fail due to the lack of percent-encoding for square brackets specifically.

This PR addresses and resolves the issue.

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@ahadalioglu ahadalioglu requested a review from a team as a code owner December 10, 2024 14:57
Copy link
Member

@basil basil left a comment

Choose a reason for hiding this comment

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

Inconsistent with #661—should call Util#rawEncode on each component of the path internally within getRelativePathFrom as suggested in #664 (comment).

@ahadalioglu
Copy link
Contributor Author

Although we used rawEncode with p.safeName and it worked, rawEncode unfortunately encodes the entire string, including slashes (/) as %2F. This becomes problematic when dealing with paths that require the slash delimiter to separate components.

To address this, I modified the hudson.Util class by adding a method called encodeEachPathComponent. This method splits the path into components using the slash (/) as a delimiter and applies encoding to each component individually.

As a result, the encoded URL now preserves the slashes while ensuring that each component is safely encoded.

Please review it at your earliest convenience.

@basil
Copy link
Member

basil commented Dec 11, 2024

To address this, I modified the hudson.Util class by adding a method called encodeEachPathComponent.

Where is the code for that method?

@ahadalioglu
Copy link
Contributor Author

ahadalioglu commented Dec 12, 2024

Oh, sorry, I have missed that:

public static String encodeEachPathComponent(String path) {
    String[] components = path.split("/");  // Split by "/"
    StringBuilder encodedPath = new StringBuilder();
    
    for (int i = 0; i < components.length; i++) {
        if (i > 0) encodedPath.append("/");  // Re-add the slash between components
        encodedPath.append(URLEncoder.encode(components[i], StandardCharsets.UTF_8));  // Encode each component
    }

    return encodedPath.toString();
}

However, I believe it would be better to revert to using rawEncode and hope it works this time.

@ahadalioglu
Copy link
Contributor Author

ahadalioglu commented Dec 12, 2024

It is done by using rawEncode method (instead of custom one offered above) to be consistent with #661.

Slashes will now also be encoded. Therefore, I propose temporarily replace only the slashes.
I will commit the changes soon.

@ahadalioglu
Copy link
Contributor Author

Now, it's ready with my above-mentioned changes.

Additionally, I have another solution:
Based on our records, the only issue with the All Failed Tests links is the brackets. If we replace just those two characters ([ and ]) with %5B and %5D, there's no need for further encoding (such as using Util/rawEncode), as there are no other issues with the broken links:

<j:set var="rawPath" value="${f.getRelativePathFrom(it)}" />
<j:set var="encodedRelativePath">
    ${rawPath.replace('[', '%5B').replace(']', '%5D')}
</j:set>

Please let me know your thoughts.

@basil
Copy link
Member

basil commented Dec 14, 2024

As stated in #667 (review) the solution should be consistent with #661 by encoding any characters that need to be encoded, not just square brackets. To accomplish this, the getRelativePathFrom code in src/main/java/hudson/tasks/test/TestObject.java needs to be updated. The call to cur.getSafeName probably needs to be wrapped in Util#rawEncode. In addition, the change needs to be tested with a test case containing square brackets.

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 this pull request may close these issues.

3 participants