Only enable BOM encoding option on UTF encodings (#8363)
Merge pull request 8363
This commit is contained in:
parent
3c46d844cf
commit
2a0272cc38
|
@ -304,12 +304,15 @@ module Jekyll
|
|||
# and a given param
|
||||
def merged_file_read_opts(site, opts)
|
||||
merged = (site ? site.file_read_opts : {}).merge(opts)
|
||||
if merged[:encoding] && !merged[:encoding].start_with?("bom|")
|
||||
|
||||
# always use BOM when reading UTF-encoded files
|
||||
if merged[:encoding]&.downcase&.start_with?("utf-")
|
||||
merged[:encoding] = "bom|#{merged[:encoding]}"
|
||||
end
|
||||
if merged["encoding"] && !merged["encoding"].start_with?("bom|")
|
||||
if merged["encoding"]&.downcase&.start_with?("utf-")
|
||||
merged["encoding"] = "bom|#{merged["encoding"]}"
|
||||
end
|
||||
|
||||
merged
|
||||
end
|
||||
|
||||
|
|
|
@ -408,13 +408,20 @@ class TestUtils < JekyllUnitTest
|
|||
assert_nil opts[:encoding]
|
||||
end
|
||||
|
||||
should "add bom to encoding" do
|
||||
should "add bom to utf-encoding" do
|
||||
opts = { "encoding" => "utf-8", :encoding => "utf-8" }
|
||||
merged = Utils.merged_file_read_opts(nil, opts)
|
||||
assert_equal "bom|utf-8", merged["encoding"]
|
||||
assert_equal "bom|utf-8", merged[:encoding]
|
||||
end
|
||||
|
||||
should "not add bom to non-utf encoding" do
|
||||
opts = { "encoding" => "ISO-8859-1", :encoding => "ISO-8859-1" }
|
||||
merged = Utils.merged_file_read_opts(nil, opts)
|
||||
assert_equal "ISO-8859-1", merged["encoding"]
|
||||
assert_equal "ISO-8859-1", merged[:encoding]
|
||||
end
|
||||
|
||||
should "preserve bom in encoding" do
|
||||
opts = { "encoding" => "bom|another", :encoding => "bom|another" }
|
||||
merged = Utils.merged_file_read_opts(nil, opts)
|
||||
|
|
Loading…
Reference in New Issue