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

Ensure spec["version"] is a string before trying to expand it #888

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion alibuild_helpers/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def resolve_version(spec, defaults, branch_basename, branch_stream):
defaults_upper = defaults != "release" and "_" + defaults.upper().replace("-", "_") or ""
commit_hash = spec.get("commit_hash", "hash_unknown")
tag = str(spec.get("tag", "tag_unknown"))
return spec["version"] % {
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure this will work correctly. For example the float 1.00 which might be intended as the version "1.00" will happily convert to "1.0". If you really want to fix this, it needs to be done at the level of the parser which should always consider "version" to be followed by a string.

return str(spec["version"]) % {
"commit_hash": commit_hash,
"short_hash": commit_hash[0:10],
"tag": tag,
Expand Down
6 changes: 6 additions & 0 deletions tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ def test_resolver(self):
self.assertTrue(resolve_version(spec, "o2", "stream/v1", "v1"), "O2")
spec["version"] = "NO%(defaults_upper)s"
self.assertTrue(resolve_version(spec, "release", "stream/v1", "v1"), "NO")
spec_float_version = {"package": "test-pkg",
"version": 1.0,
"tag": "foo/bar",
"commit_hash": "000000000000000000000000000"
}
self.assertTrue(resolve_version(spec_float_version, "release", "stream/v1", "v1"), "NO")


class TestTopologicalSort(unittest.TestCase):
Expand Down
Loading