Skip to content

fix: discard dot segments from subpath #176

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

dwalluck
Copy link
Contributor

@dwalluck dwalluck commented Mar 4, 2025

This change makes the two test pass that were introduced in package-url/purl-spec#368.

See also package-url/purl-spec#404.

Copy link
Contributor

@ppkarwasz ppkarwasz left a comment

Choose a reason for hiding this comment

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

My 2 cents:

@dwalluck dwalluck force-pushed the fix-parse-path branch 3 times, most recently from 6cb7290 to 8a03dd6 Compare March 17, 2025 15:27
Comment on lines 434 to 464
if (".".equals(segment) || "..".equals(segment)) {
if (!isSubpath) {
throw new MalformedPackageURLException("Segments in the namespace must not be a period ('.') or repeated period ('..'): '" + segment + "'");
}
Copy link
Contributor Author

@dwalluck dwalluck Mar 17, 2025

Choose a reason for hiding this comment

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

I can't actually find any mention of namespace not containing dots, but I left the code as it was.

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the condition inverted? Segments in the subpath can not be neither . nor .., but no such condition exists for namespace.

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 agree that it looks inverted compared to the original code, but I think it is the behavior intended by the test cases:

  • If !subpath, i.e., namespace, then if . or .. appears it's an error.
  • If subpath, then discard it without error and don't add it to the results.

Copy link
Contributor Author

@dwalluck dwalluck Mar 18, 2025

Choose a reason for hiding this comment

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

I think it's confusing because there are two methods, parsePath and validatePath, and they don't share the same code.

One is pre-decoding and silently filters paths there, and one is post-decoding. Probably, there is some way to refactor it to make this clearer, but I haven't figured it out yet.

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 added a test case. Does it make sense?

@dwalluck dwalluck force-pushed the fix-parse-path branch 4 times, most recently from 6fc05ab to db191ad Compare March 17, 2025 15:54
@dwalluck dwalluck changed the title Silently drop empty and dot segments for subpath Discard dot segments from subpath Mar 17, 2025
@dwalluck dwalluck force-pushed the fix-parse-path branch 3 times, most recently from 2fa4d68 to c4171ea Compare March 17, 2025 16:39
Comment on lines 434 to 464
if (".".equals(segment) || "..".equals(segment)) {
if (!isSubpath) {
throw new MalformedPackageURLException("Segments in the namespace must not be a period ('.') or repeated period ('..'): '" + segment + "'");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the condition inverted? Segments in the subpath can not be neither . nor .., but no such condition exists for namespace.

Comment on lines 176 to 177
assertEquals(subpath, purl.getSubpath());
//assertEquals(subpath, purl.getSubpath());
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I was told that we were using the test suite incorrectly, and that we shouldn't compare the fields at all.

After berating me for even pointing out that there was an issue with the tests because these two tests introduced a different representation of the fields (original instead of canonical), they finally settled on changing the test suite so that all fields were original. At least there's an open pull request for that now.

So, either we'll end up having to remove everything except string comparison in our tests, or they'll finally settle on something. I am sort of against fixing the test suite locally in our copy, though, because we don't even know their intention.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, it was @jeremylong that submitted these tests upstream, so we can find out exactly what was intended with the fields. Was it a mistake or not? The tests don't pass with the current Java code and what do we do now about the fact that even after the "fix" in this pull request the Java code is failing the subpath comparison.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Before continuing this one we may want to wait for the spec to be updated a bit - per comments like: package-url/purl-spec#409 (comment)

I know at least one of my changes to the test case is being reverted due to a misunderstanding/wording of the spec.

@dwalluck dwalluck changed the title Discard dot segments from subpath fix: discard dot segments from subpath Mar 18, 2025
@ppkarwasz
Copy link
Contributor

Now that Spotless is there, there will be some conflicts. This should help:

git checkout origin/master -- pom.xml
mvn spotless:apply

This change makes the two test pass that were introduced in
package-url/purl-spec#368.

See also package-url/purl-spec#404.
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