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

Handle empty package name in mix hex.info #1022

Merged
merged 2 commits into from
May 6, 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
8 changes: 4 additions & 4 deletions lib/hex/api/package.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Hex.API.Package do

alias Hex.API

def get(repo, name, auth \\ []) do
def get(repo, name, auth \\ []) when name != "" do
path = "packages/#{URI.encode(name)}"
API.request(:get, repo, path, auth)
end
Expand All @@ -16,7 +16,7 @@ defmodule Hex.API.Package do
defmodule Owner do
@moduledoc false

def add(repo, package, owner, level, transfer, auth) do
def add(repo, package, owner, level, transfer, auth) when package != "" do
Hex.API.check_write_api()

owner = URI.encode_www_form(owner)
Expand All @@ -25,15 +25,15 @@ defmodule Hex.API.Package do
API.erlang_put_request(repo, path, params, auth)
end

def delete(repo, package, owner, auth) do
def delete(repo, package, owner, auth) when package != "" do
Hex.API.check_write_api()

owner = URI.encode_www_form(owner)
path = "packages/#{URI.encode(package)}/owners/#{URI.encode(owner)}"
API.request(:delete, repo, path, auth)
end

def get(repo, package, auth) do
def get(repo, package, auth) when package != "" do
API.request(:get, repo, "packages/#{URI.encode(package)}/owners", auth)
end
end
Expand Down
5 changes: 5 additions & 0 deletions lib/mix/tasks/hex.info.ex
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ defmodule Mix.Tasks.Hex.Info do
Hex.Registry.Server.close()
end

defp package(_organization, "") do
Hex.Shell.error("Package name is empty")
Mix.Tasks.Hex.set_exit_code(1)
end

defp package(organization, package) do
auth = organization && Mix.Tasks.Hex.auth_info(:read)

Expand Down
3 changes: 3 additions & 0 deletions test/mix/tasks/hex.info_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ defmodule Mix.Tasks.Hex.InfoTest do

assert catch_throw(Mix.Tasks.Hex.Info.run(["no_package"])) == {:exit_code, 1}
assert_received {:mix_shell, :error, ["No package with name no_package"]}

assert catch_throw(Mix.Tasks.Hex.Info.run([""])) == {:exit_code, 1}
assert_received {:mix_shell, :error, ["Package name is empty"]}
end

test "locked package" do
Expand Down
Loading