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

[MNG-6535] Improve test coverage of UrlNormalizer. #264

Conversation

josephw
Copy link
Contributor

@josephw josephw commented Jun 30, 2019

Refine the original PR (#199) to the test that improves coverage and give it a clearer description of its behaviour.

Although this isn't a major change, it does improve coverage (this case works, but isn't currently tested), and resolves the original ticket.

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Make sure there is a JIRA issue filed
    for the change (usually before you start working on it). Trivial changes like typos do not
    require a JIRA issue. Your pull request should address just this issue, without
    pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [MNG-XXX] - Fixes bug in ApproximateQuantiles,
    where you replace MNG-XXX with the appropriate JIRA issue. Best practice
    is to use the JIRA issue title in the pull request title and in the first line of the
    commit message.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean verify to make sure basic checks pass. A more thorough check will
    be performed on your pull request automatically.
  • You have run the Core IT successfully.

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

Refine the original PR to the test that improves coverage;
give it a clearer description of its behaviour.
asfgit pushed a commit that referenced this pull request Jul 1, 2019
public void testNormalizeInputWithNoParentDirectoriesToAscendTo()
{
assertEquals("a/../", normalize("a/../"));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe the implementation is wrong, but comparing this with Path this is the result:

    assertEquals( "a/../",  Paths.get("a/../").normalize().toString() ); // fails
    assertEquals( "",  Paths.get("a/../").normalize().toString() ); // succeeds

The Path behavior is also what I would expect.

Copy link
Member

Choose a reason for hiding this comment

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

@rfscholte So our impl is wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure it's worth changing the behaviour; this class is used with absolute URLs (or paths), so this is very much an edge case.

However, I think it's (slightly) valuable to test that this case doesn't cause an error -- perhaps a different test name could make that clear?

Copy link
Member

Choose a reason for hiding this comment

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

If we normalize URLs, the test for relative paths must fail. URLs are absolute.

Copy link
Member

Choose a reason for hiding this comment

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

@josephw Please raise an issue that our impl is wrong. Otherwise we will lose the findings here. Then I will add a comment abour the test referring to the new ticket and merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thinking again; there's no reason to retain the existing behaviour if it's wrong. The change to match Path is simple enough, and doesn't break the existing tests: I've pushed it.

Ideally, the interface would be clearer about its contract, but this is the least surprising behaviour.

This method could be passed relative URIs, so improve handling rather
than doubling down on the existing behaviour. Normalize relative URIs
to remove redundant '../'.

Also switch to JUnit annotations and drop some boilerplate.
Copy link
Member

@michael-o michael-o left a comment

Choose a reason for hiding this comment

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

Looks better now. Since you have changed (fixed) the impl, we need to turn the issue into a bug.

public void testNormalizeInputWithNoParentDirectoriesToAscendTo()
{
assertEquals("a/../", normalize("a/../"));
}
Copy link
Member

Choose a reason for hiding this comment

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

@josephw Please raise an issue that our impl is wrong. Otherwise we will lose the findings here. Then I will add a comment abour the test referring to the new ticket and merge.

@Test
public void relativeUriReferenceLeftUnaffectedWithNoParentDirectoryToAscendTo()
{
assertEquals( "/../", normalize("/../" ) );
Copy link
Member

Choose a reason for hiding this comment

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

Did you test the same with Path?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Path and URI differ slightly here; I've gone with RFC 3986's Remove Dot Segments and adjusted the code to remove them.

* Adopt RFC 3968's behaviour for traversal past the root
* Add a test that this isn't applied to relative URI references
@josephw
Copy link
Contributor Author

josephw commented Jul 8, 2019

Looks better now. Since you have changed (fixed) the impl, we need to turn the issue into a bug.

I've opened MNG-6703.

@michael-o
Copy link
Member

PAsses for me locally, waiting for Jenkins..

@asfgit asfgit closed this in 4fa882c Jul 10, 2019
gnodet added a commit to gnodet/maven that referenced this pull request Nov 20, 2024
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