[Bugfix] Properly escape NFO files (#168)
* Properly escaped NFO file contents * Added an NFO backfill worker * Added a try-catch to the backfill since I _really_ don't want failures to halt app boot
This commit is contained in:
@@ -30,6 +30,21 @@ defmodule Pinchflat.Metadata.NfoBuilderTest do
|
||||
assert String.contains?(nfo, ~S(<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>))
|
||||
assert String.contains?(nfo, "<title>#{metadata["title"]}</title>")
|
||||
end
|
||||
|
||||
test "escapes invalid characters", %{filepath: filepath} do
|
||||
metadata = %{
|
||||
"title" => "hello' & <world>",
|
||||
"uploader" => "uploader",
|
||||
"id" => "id",
|
||||
"description" => "description",
|
||||
"upload_date" => "20210101"
|
||||
}
|
||||
|
||||
result = NfoBuilder.build_and_store_for_media_item(filepath, metadata)
|
||||
nfo = File.read!(result)
|
||||
|
||||
assert String.contains?(nfo, "hello' & <world>")
|
||||
end
|
||||
end
|
||||
|
||||
describe "build_and_store_for_source/2" do
|
||||
@@ -46,5 +61,18 @@ defmodule Pinchflat.Metadata.NfoBuilderTest do
|
||||
assert String.contains?(nfo, ~S(<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>))
|
||||
assert String.contains?(nfo, "<title>#{metadata["title"]}</title>")
|
||||
end
|
||||
|
||||
test "escapes invalid characters", %{filepath: filepath} do
|
||||
metadata = %{
|
||||
"title" => "hello' & <world>",
|
||||
"description" => "description",
|
||||
"id" => "id"
|
||||
}
|
||||
|
||||
result = NfoBuilder.build_and_store_for_source(filepath, metadata)
|
||||
nfo = File.read!(result)
|
||||
|
||||
assert String.contains?(nfo, "hello' & <world>")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
defmodule Pinchflat.Utils.XmlUtilsTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
alias Pinchflat.Utils.XmlUtils
|
||||
|
||||
describe "safe/1" do
|
||||
test "escapes invalid characters" do
|
||||
assert XmlUtils.safe("hello' & <world>") == "hello' & <world>"
|
||||
end
|
||||
|
||||
test "converts input to string" do
|
||||
assert XmlUtils.safe(42) == "42"
|
||||
assert XmlUtils.safe(nil) == ""
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user