tolerate spaces in tags

This commit is contained in:
shibao 2023-11-04 22:07:25 -04:00
parent 1d6ba5960c
commit d5e334dc09
10 changed files with 40 additions and 39 deletions

View File

@ -1,6 +1,7 @@
# v0.1.13
- Update dependencies
- Fix debounces
- Allow space as delimiter for tags
# v0.1.12
- Code quality fixes

View File

@ -79,11 +79,11 @@ defmodule Memex.Contexts.Context do
changeset
|> put_change(:tags_string, changeset |> get_field(:tags) |> get_tags_string())
|> cast(attrs, [:tags_string])
|> validate_format(:tags_string, ~r/^[\p{L}\p{N}\-\,]+$/,
|> validate_format(:tags_string, ~r/^[\p{L}\p{N}\-\, ]+$/,
message:
dgettext(
"errors",
"invalid format: only numbers, letters and hyphen are accepted. tags must be comma-delimited"
"invalid format: only numbers, letters and hyphen are accepted. tags must be comma or space delimited"
)
)
|> cast_tags()
@ -98,9 +98,9 @@ defmodule Memex.Contexts.Context do
defp process_tags(tags_string) when tags_string |> is_binary() do
tags_string
|> String.split(",", trim: true)
|> String.split([",", " "], trim: true)
|> Enum.map(fn str -> str |> String.trim() end)
|> Enum.reject(fn str -> str |> is_nil() end)
|> Enum.reject(fn str -> str in [nil, ""] end)
|> Enum.sort()
end

View File

@ -78,11 +78,11 @@ defmodule Memex.Notes.Note do
changeset
|> put_change(:tags_string, changeset |> get_field(:tags) |> get_tags_string())
|> cast(attrs, [:tags_string])
|> validate_format(:tags_string, ~r/^[\p{L}\p{N}\-\,]+$/,
|> validate_format(:tags_string, ~r/^[\p{L}\p{N}\-\, ]+$/,
message:
dgettext(
"errors",
"invalid format: only numbers, letters and hyphen are accepted. tags must be comma-delimited"
"invalid format: only numbers, letters and hyphen are accepted. tags must be comma or space delimited"
)
)
|> cast_tags()
@ -97,9 +97,9 @@ defmodule Memex.Notes.Note do
defp process_tags(tags_string) when tags_string |> is_binary() do
tags_string
|> String.split(",", trim: true)
|> String.split([",", " "], trim: true)
|> Enum.map(fn str -> str |> String.trim() end)
|> Enum.reject(fn str -> str |> is_nil() end)
|> Enum.reject(fn str -> str in [nil, ""] end)
|> Enum.sort()
end

View File

@ -81,11 +81,11 @@ defmodule Memex.Pipelines.Pipeline do
changeset
|> put_change(:tags_string, changeset |> get_field(:tags) |> get_tags_string())
|> cast(attrs, [:tags_string])
|> validate_format(:tags_string, ~r/^[\p{L}\p{N}\-\,]+$/,
|> validate_format(:tags_string, ~r/^[\p{L}\p{N}\-\, ]+$/,
message:
dgettext(
"errors",
"invalid format: only numbers, letters and hyphen are accepted. tags must be comma-delimited"
"invalid format: only numbers, letters and hyphen are accepted. tags must be comma or space delimited"
)
)
|> cast_tags()
@ -100,9 +100,9 @@ defmodule Memex.Pipelines.Pipeline do
defp process_tags(tags_string) when tags_string |> is_binary() do
tags_string
|> String.split(",", trim: true)
|> String.split([",", " "], trim: true)
|> Enum.map(fn str -> str |> String.trim() end)
|> Enum.reject(fn str -> str |> is_nil() end)
|> Enum.reject(fn str -> str in [nil, ""] end)
|> Enum.sort()
end

View File

@ -79,13 +79,6 @@ msgstr ""
msgid "unauthorized"
msgstr ""
#: lib/memex/contexts/context.ex:84
#: lib/memex/notes/note.ex:83
#: lib/memex/pipelines/pipeline.ex:86
#, elixir-autogen, elixir-format, fuzzy
msgid "invalid format: only numbers, letters and hyphen are accepted. tags must be comma-delimited"
msgstr ""
#: lib/memex_web/controllers/user_registration_html/new.html.heex:13
#: lib/memex_web/controllers/user_reset_password_html/edit.html.heex:13
#: lib/memex_web/controllers/user_settings_html/edit.html.heex:64
@ -146,3 +139,10 @@ msgstr ""
#, elixir-autogen, elixir-format, fuzzy
msgid "user confirmation link is invalid or it has expired."
msgstr ""
#: lib/memex/contexts/context.ex:84
#: lib/memex/notes/note.ex:83
#: lib/memex/pipelines/pipeline.ex:86
#, elixir-autogen, elixir-format, fuzzy
msgid "invalid format: only numbers, letters and hyphen are accepted. tags must be comma or space delimited"
msgstr ""

View File

@ -80,13 +80,6 @@ msgstr ""
msgid "unauthorized"
msgstr ""
#: lib/memex/contexts/context.ex:84
#: lib/memex/notes/note.ex:83
#: lib/memex/pipelines/pipeline.ex:86
#, elixir-autogen, elixir-format
msgid "invalid format: only numbers, letters and hyphen are accepted. tags must be comma-delimited"
msgstr ""
#: lib/memex_web/controllers/user_registration_html/new.html.heex:13
#: lib/memex_web/controllers/user_reset_password_html/edit.html.heex:13
#: lib/memex_web/controllers/user_settings_html/edit.html.heex:64
@ -147,3 +140,10 @@ msgstr ""
#, elixir-autogen, elixir-format, fuzzy
msgid "user confirmation link is invalid or it has expired."
msgstr ""
#: lib/memex/contexts/context.ex:84
#: lib/memex/notes/note.ex:83
#: lib/memex/pipelines/pipeline.ex:86
#, elixir-autogen, elixir-format, fuzzy
msgid "invalid format: only numbers, letters and hyphen are accepted. tags must be comma or space delimited"
msgstr ""

View File

@ -79,13 +79,6 @@ msgstr ""
msgid "unauthorized"
msgstr ""
#: lib/memex/contexts/context.ex:84
#: lib/memex/notes/note.ex:83
#: lib/memex/pipelines/pipeline.ex:86
#, elixir-autogen, elixir-format
msgid "invalid format: only numbers, letters and hyphen are accepted. tags must be comma-delimited"
msgstr ""
#: lib/memex_web/controllers/user_registration_html/new.html.heex:13
#: lib/memex_web/controllers/user_reset_password_html/edit.html.heex:13
#: lib/memex_web/controllers/user_settings_html/edit.html.heex:64
@ -146,3 +139,10 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "user confirmation link is invalid or it has expired."
msgstr ""
#: lib/memex/contexts/context.ex:84
#: lib/memex/notes/note.ex:83
#: lib/memex/pipelines/pipeline.ex:86
#, elixir-autogen, elixir-format
msgid "invalid format: only numbers, letters and hyphen are accepted. tags must be comma or space delimited"
msgstr ""

View File

@ -17,7 +17,7 @@ defmodule MemexWeb.ContextLiveTest do
}
@invalid_attrs %{
content: nil,
tags_string: "invalid tags",
tags_string: "invalid_tag or_tags",
slug: nil,
visibility: nil
}
@ -114,7 +114,7 @@ defmodule MemexWeb.ContextLiveTest do
|> render_change(context: @invalid_attrs)
assert html =~ "can't be blank"
assert html =~ "tags must be comma-delimited"
assert html =~ "tags must be comma or space delimited"
{:ok, _live, html} =
show_live

View File

@ -17,7 +17,7 @@ defmodule MemexWeb.NoteLiveTest do
}
@invalid_attrs %{
content: nil,
tags_string: "invalid tags",
tags_string: "invalid_tag or_tags",
slug: nil,
visibility: nil
}
@ -55,7 +55,7 @@ defmodule MemexWeb.NoteLiveTest do
|> render_change(note: @invalid_attrs)
assert html =~ "can't be blank"
assert html =~ "tags must be comma-delimited"
assert html =~ "tags must be comma or space delimited"
{:ok, _live, html} =
index_live

View File

@ -17,7 +17,7 @@ defmodule MemexWeb.PipelineLiveTest do
}
@invalid_attrs %{
description: nil,
tags_string: "invalid tags",
tags_string: "invalid_tag or_tags",
slug: nil,
visibility: nil
}
@ -130,7 +130,7 @@ defmodule MemexWeb.PipelineLiveTest do
|> render_change(pipeline: @invalid_attrs)
assert html =~ "can't be blank"
assert html =~ "tags must be comma-delimited"
assert html =~ "tags must be comma or space delimited"
{:ok, _live, html} =
show_live