Declare UTF-8 in HTML layouts; byte order mark on packaged CSVs

Packaged HTML opened from disk had no charset, so browsers guessed
Windows-1252 and em dashes showed as mojibake; Excel does the same with
CSVs that lack a BOM.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-07 17:24:53 -05:00
1 parent 5471b9317f
commit 350914bddc
5 files changed
+9 -1

No files matched your search

+3
View File
@@ -37,7 +37,10 @@ class RecordsPackage
private private
# CSVs start with a UTF-8 byte order mark so Excel reads accents, dashes
# and quotes correctly (without it, it guesses another encoding).
def add(zip, name, content) def add(zip, name, content)
content = "\uFEFF#{content}" if name.end_with?(".csv") && !content.start_with?("\uFEFF")
zip.put_next_entry(name) zip.put_next_entry(name)
zip.write(content) zip.write(content)
end end
+1
View File
@@ -1,6 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html class="h-full bg-page"> <html class="h-full bg-page">
<head> <head>
<meta charset="utf-8">
<%= render "shared/theme_script" %> <%= render "shared/theme_script" %>
<title><%= [content_for(:title), "Simple Aircraft Manager"].compact.join(" · ") %></title> <title><%= [content_for(:title), "Simple Aircraft Manager"].compact.join(" · ") %></title>
<meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="viewport" content="width=device-width,initial-scale=1">
+1
View File
@@ -1,6 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html class="h-full bg-page"> <html class="h-full bg-page">
<head> <head>
<meta charset="utf-8">
<%= render "shared/theme_script" %> <%= render "shared/theme_script" %>
<title><%= [content_for(:title), "Simple Aircraft Manager"].compact.join(" · ") %></title> <title><%= [content_for(:title), "Simple Aircraft Manager"].compact.join(" · ") %></title>
<meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="viewport" content="width=device-width,initial-scale=1">
+1
View File
@@ -1,6 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html class="bg-white" data-theme="light"> <html class="bg-white" data-theme="light">
<head> <head>
<meta charset="utf-8">
<title><%= [content_for(:title), "Simple Aircraft Manager"].compact.join(" · ") %></title> <title><%= [content_for(:title), "Simple Aircraft Manager"].compact.join(" · ") %></title>
<meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="robots" content="noindex, nofollow"> <meta name="robots" content="noindex, nofollow">
+3 -1
View File
@@ -91,6 +91,7 @@ class RecordsIntegrityTest < ActionDispatch::IntegrationTest
html = zip.text("status-report.html") html = zip.text("status-report.html")
assert_includes html, "Maintenance status · 14 CFR 91.417(a)(2)" assert_includes html, "Maintenance status · 14 CFR 91.417(a)(2)"
refute_includes html, "<script" refute_includes html, "<script"
assert_match(/<head>\s*<meta charset="utf-8">/, html) # files opened from disk need it (em dashes etc.)
assert_includes html, "<style>" assert_includes html, "<style>"
end end
assert @a.events.exists?(event_name: "Records package downloaded") assert @a.events.exists?(event_name: "Records package downloaded")
@@ -116,7 +117,8 @@ class RecordsIntegrityTest < ActionDispatch::IntegrationTest
engine = create_component(@a, tbo_hours: 2000, hours_since_overhaul: 126, on_condition: true) engine = create_component(@a, tbo_hours: 2000, hours_since_overhaul: 126, on_condition: true)
path = Rails.root.join("tmp", "pkg-#{SecureRandom.hex(4)}.zip") path = Rails.root.join("tmp", "pkg-#{SecureRandom.hex(4)}.zip")
RecordsPackage.new(@a, source: "test").write_to(path) RecordsPackage.new(@a, source: "test").write_to(path)
html = Zip::File.open(path) { |z| z.read("status-report.html").force_encoding("UTF-8") } html, csv = Zip::File.open(path) { |z| [ z.read("status-report.html").force_encoding("UTF-8"), z.read("signatures.csv").force_encoding("UTF-8") ] }
assert csv.start_with?("\uFEFF"), "CSV has a byte order mark for Excel"
File.delete(path) File.delete(path)
assert_includes html, "<style>" assert_includes html, "<style>"
refute_includes html, "\\[</head>" # escaped "&" in CSS selectors left intact refute_includes html, "\\[</head>" # escaped "&" in CSS selectors left intact