Escape - and . in regex character class, closes #3040

This commit is contained in:
José Valim 2025-08-06 16:33:34 +02:00
parent 036681ecb3
commit 5ce550fd5f

View file

@ -953,7 +953,7 @@ defmodule Livebook.Notebook do
@spec validate_file_entry_name(Ecto.Changeset.t(), atom()) :: Ecto.Changeset.t() @spec validate_file_entry_name(Ecto.Changeset.t(), atom()) :: Ecto.Changeset.t()
def validate_file_entry_name(changeset, field) do def validate_file_entry_name(changeset, field) do
changeset changeset
|> Ecto.Changeset.validate_format(field, ~r/^[\w-.]+$/, |> Ecto.Changeset.validate_format(field, ~r/^[\w\-\.]+$/,
message: "should contain only alphanumeric characters, dash, underscore and dot" message: "should contain only alphanumeric characters, dash, underscore and dot"
) )
|> Ecto.Changeset.validate_format(field, ~r/\.\w+$/, message: "should end with an extension") |> Ecto.Changeset.validate_format(field, ~r/\.\w+$/, message: "should end with an extension")