mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-02-02 12:18:20 +08:00
Fix generating html id with special characters (#2495)
This commit is contained in:
parent
4105266ad2
commit
bd3232dedb
2 changed files with 8 additions and 3 deletions
|
@ -34,9 +34,14 @@ defmodule LivebookWeb.HTMLHelpers do
|
|||
|
||||
defp name_to_html_id(name) do
|
||||
name
|
||||
|> String.trim()
|
||||
|> String.downcase()
|
||||
|> String.replace(~r/[^\s\w]/u, "")
|
||||
|> String.trim()
|
||||
|> String.replace(~r/\s+/u, "-")
|
||||
|> case do
|
||||
"" -> Base.url_encode64(name, padding: false)
|
||||
id -> id
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
|
@ -18,11 +18,11 @@ defmodule LivebookWeb.HTMLHelpersTest do
|
|||
end
|
||||
|
||||
test "emoji at end" do
|
||||
assert HTMLHelpers.names_to_html_ids(["Test 🦦 "]) == ["test-🦦"]
|
||||
assert HTMLHelpers.names_to_html_ids(["Test 🦦 "]) == ["test"]
|
||||
end
|
||||
|
||||
test "emoji in middle" do
|
||||
assert HTMLHelpers.names_to_html_ids(["One 🥮 Two"]) == ["one-🥮-two"]
|
||||
assert HTMLHelpers.names_to_html_ids(["One 🥮 Two"]) == ["one-two"]
|
||||
end
|
||||
|
||||
test "returns empty list for an empty list" do
|
||||
|
|
Loading…
Reference in a new issue