mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-01-27 17:27:51 +08:00
Remove non-ascii characters from autogenerated notebook file names (#1068)
This commit is contained in:
parent
918216980e
commit
7f39c6be76
2 changed files with 11 additions and 2 deletions
|
@ -1400,8 +1400,9 @@ defmodule Livebook.Session do
|
|||
defp notebook_name_to_file_name(notebook_name) do
|
||||
notebook_name
|
||||
|> String.downcase()
|
||||
|> String.replace(~r/\s+/, "_")
|
||||
|> String.replace(~r/[^\w]/, "")
|
||||
|> String.replace(~r/[^\s\w]/u, "")
|
||||
|> String.trim()
|
||||
|> String.replace(~r/\s+/u, "_")
|
||||
|> case do
|
||||
"" -> "untitled_notebook"
|
||||
name -> name
|
||||
|
|
|
@ -29,6 +29,14 @@ defmodule Livebook.SessionTest do
|
|||
|
||||
assert Session.file_name_for_download(session) == "cats_guide_to_life"
|
||||
end
|
||||
|
||||
test "removes non-ascii characters from notebook name", %{session: session} do
|
||||
Session.set_notebook_name(session.pid, "Notebook 😺")
|
||||
# Get the updated struct
|
||||
session = Session.get_by_pid(session.pid)
|
||||
|
||||
assert Session.file_name_for_download(session) == "notebook"
|
||||
end
|
||||
end
|
||||
|
||||
describe "set_notebook_attributes/2" do
|
||||
|
|
Loading…
Reference in a new issue