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

Add check that commit ID is valid hexadecimal #1740

Merged
merged 1 commit into from
Aug 19, 2024
Merged
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
4 changes: 2 additions & 2 deletions src/alire/alire-origins.adb
Original file line number Diff line number Diff line change
Expand Up @@ -427,14 +427,14 @@ package body Alire.Origins is
begin
case Scheme is
when Pure_Git | Git | HTTP =>
if Commit'Length /= Git_Commit'Length then
if not Is_Valid_Commit (Commit) then
Raise_Checked_Error
("invalid git commit id, " &
"40 digits hexadecimal expected");
end if;
return New_Git (VCS_URL, Commit, Subdir);
when Hg =>
if Commit'Length /= Hg_Commit'Length then
if not Is_Valid_Mercurial_Commit (Commit) then
Raise_Checked_Error
("invalid mercurial commit id, " &
"40 digits hexadecimal expected");
Expand Down
4 changes: 4 additions & 0 deletions src/alire/alire-origins.ads
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ package Alire.Origins is
is (S'Length = Git_Commit'Length and then
(for all Char of S => Char in Alire.Utils.Hexadecimal_Character));

function Is_Valid_Mercurial_Commit (S : String) return Boolean
is (S'Length = Hg_Commit'Length and then
(for all Char of S => Char in Alire.Utils.Hexadecimal_Character));

function Short_Commit (Commit : String) return String;
-- First characters in the commit

Expand Down
10 changes: 10 additions & 0 deletions testsuite/tests/publish/bad-arguments/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@
assert_match(".*invalid git commit id, 40 digits hexadecimal expected.*",
p.out)

# Bad commit characters
p = run_alr("publish", "git+http://github.com/repo", "_"*40,
complain_on_error=False)
assert_match(".*invalid git commit id, 40 digits hexadecimal expected.*",
p.out)
p = run_alr("publish", "hg+http://host.name/repo", "_"*40,
complain_on_error=False)
assert_match(".*invalid mercurial commit id, 40 digits hexadecimal expected.*",
p.out)

# VCS without transport or extension
p = run_alr("publish", "http://somehost.com/badrepo", "deadbeef",
complain_on_error=False)
Expand Down
Loading