Fix substring matching on cpan and mlflow type checks#232
Open
arpitjain099 wants to merge 2 commits into
Open
Conversation
The cpan and mlflow branches used `ptype in ("cpan")` and
`ptype in ("mlflow")`. The missing trailing comma makes each a plain
string rather than a one-element tuple, so `in` is a substring test
instead of an equality test.
Any type that is a substring of the literal took the branch. For
example pkg:pan/Some-Namespace/x had its namespace uppercased to
SOME-NAMESPACE, and a name normalized under type "flow" took the
mlflow path and was lowercased when a databricks repository_url
qualifier was present.
Use == to match the neighbouring pypi, hackage and pub checks.
Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Both the cpan and the mlflow type checks are missing a trailing comma:
("cpan")is just the string"cpan", not a one-element tuple, soinruns a substring test instead of an equality test. Any type that happens to be a substring of the literal takes the branch.On current main:
The namespace gets uppercased because
"pan" in "cpan"is true. Same for"c","cpa","an"and so on. The mlflow one is the same shape, and it returns early, so a name normalized under type"flow"goes down the mlflow path and gets lowercased when arepository_urldatabricks qualifier is set.No currently registered purl type is a substring of either literal, so this isn't biting a spec type today. It is reachable right now though, since arbitrary types are accepted, and it silently corrupts the namespace or name rather than erroring.
Switched both to
==, which is what the pypi, hackage and pub checks a few lines down already use. I also dropped the now-redundantptype andguard since== "cpan"is already false forNoneand"".I grepped the rest of
src/for the samein ("...")single-string shape and these two are the only instances.Tests: added two cases to
tests/test_packageurl.pycovering both. Reverting the source change and keeping the tests fails them:With the fix,
pytest testsis 987 passed.black --line-length 100,isort --profile blackandmypyare clean.One note on overlap: #188 adds
PURL_TYPESand touches this file, but it only adds a constant near the top and doesn't change these two lines, so it shouldn't conflict.