Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule LuxpkgsRockspecVerifier.Rockspec do
}) do
sandboxed_state = :luerl_sandbox.init()

Regex.match?(~r/^[a-zA-Z0-9_\-]+$/, expected_name) and
Regex.match?(~r/^[a-zA-Z0-9_\.\-]+$/, expected_name) and
case :luerl_sandbox.run(
rockspec,
%{
Expand Down
2 changes: 1 addition & 1 deletion luxpkgs/lib/luxpkgs/packages/package.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule Luxpkgs.Packages.Package do
|> cast(attrs, [:name])
|> validate_required([:name])
|> unique_constraint(:name)
|> validate_format(:name, ~r/^[a-zA-Z0-9_\-]+$/)
|> validate_format(:name, ~r/^[a-zA-Z0-9_\.\-]+$/)
# Recast here to prevent the user from changing the package name
|> cast(attrs, [:summary, :description])
|> validate_length(:name, min: 1, max: 20)
Expand Down
16 changes: 13 additions & 3 deletions luxpkgs/lib/luxpkgs_web/controllers/luarocks_api_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,12 @@ defmodule LuxpkgsWeb.LuaRocksApiController do
|> put_status(:service_unavailable)
|> json(%{errors: ["Rockspec verifier service is unavailable"]})

{:error, %Ecto.Changeset{}} ->
put_status(conn, :bad_request)
{:error, %Ecto.Changeset{} = changeset} ->
conn
|> put_status(:bad_request)
|> json(%{
errors: Enum.map(changeset.errors, fn {field, {msg, _}} -> "#{field} #{msg}" end)
})

{:error, reason} ->
conn
Expand Down Expand Up @@ -146,7 +150,13 @@ defmodule LuxpkgsWeb.LuaRocksApiController do

case Req.post(endpoint, json: %{rockspec: rockspec_text}) do
{:ok, %Req.Response{status: 200, body: body}} ->
{:ok, body}
{:ok,
%{
package: body["package"],
version: body["version"],
summary: body["summary"],
description: body["description"]
}}

{:ok, %Req.Response{status: 422}} ->
{:error, :invalid_rockspec}
Expand Down
2 changes: 1 addition & 1 deletion luxpkgs/lib/luxpkgs_web/schemas/package_input.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule LuxpkgsWeb.Schemas.PackageInput do
type: :string,
description: "Unique package name",
example: "lua-cjson",
pattern: "^[a-zA-Z0-9_-]+$"
pattern: "^[a-zA-Z0-9_.-]+$"
},
summary: %OpenApiSpex.Schema{
type: :string,
Expand Down
Loading