Remove non-ascii characters from autogenerated notebook file names (#1068)

This commit is contained in:
Jonatan Kłosko 2022-03-22 21:54:59 +01:00 committed by GitHub
parent 918216980e
commit 7f39c6be76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View file

@ -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

View file

@ -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