diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 61f3b78c85d..183c3bac11e 100755
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -61,16 +61,11 @@ def link_to_rss(link_to_feed)
link_to content_tag(:span, ts("RSS Feed")), link_to_feed, title: ts("RSS Feed"), class: "rss"
end
- #1: default shows just the link to help
- #2: show_text = true: shows "plain text with limited html" and link to help
- #3 show_list = true: plain text and limited html, link to help, list of allowed html
- def allowed_html_instructions(show_list = false, show_text=true)
- (show_text ? h(ts("Plain text with limited HTML")) : ''.html_safe) +
- link_to_help("html-help") + (show_list ?
- "a, abbr, acronym, address, [alt], [axis], b, big, blockquote, br, caption, center, cite, [class], code,
- col, colgroup, dd, del, dfn, [dir], div, dl, dt, em, h1, h2, h3, h4, h5, h6, [height], hr, [href], i, img,
- ins, kbd, li, [name], ol, p, pre, q, s, samp, small, span, [src], strike, strong, sub, sup, table, tbody, td,
- tfoot, th, thead, [title], tr, tt, u, ul, var, [width]
" : "").html_safe
+ # 1: default shows just the link to help
+ # 2: show_text = true: shows "plain text with limited html" and link to help
+ def allowed_html_instructions(show_text = true)
+ (show_text ? h(ts("Plain text with limited HTML")) : "".html_safe) +
+ link_to_help("html-help")
end
# Byline helpers
diff --git a/app/views/bookmarks/_bookmark_form.html.erb b/app/views/bookmarks/_bookmark_form.html.erb
index 77c61174dfb..05e1e9bd3e7 100644
--- a/app/views/bookmarks/_bookmark_form.html.erb
+++ b/app/views/bookmarks/_bookmark_form.html.erb
@@ -65,7 +65,7 @@
<% if bookmarkable.class != ExternalWork %>
<%= ts("The creator's summary is added automatically.") %>
<% end %>
- <%= allowed_html_instructions(show_list = false) %>
+ <%= allowed_html_instructions %>
<%= f.text_area :bookmarker_notes, rows: 4, id: notes_id, class: "observe_textlength",
"aria-describedby" => "notes-field-description" %>
diff --git a/app/views/comments/_comment_form.html.erb b/app/views/comments/_comment_form.html.erb
index c6b5e658bf9..a6469663e72 100644
--- a/app/views/comments/_comment_form.html.erb
+++ b/app/views/comments/_comment_form.html.erb
@@ -48,7 +48,7 @@
<%= ts("to") %> <%= get_commenter_pseud_or_name(commentable) %> <%= ts("on") %> <%= commentable_description_link(commentable) %>
<% end %>
<% end %>
- (<%= allowed_html_instructions(show_list=false) %>)
+ (<%= allowed_html_instructions %>)
<% else %>
<%= ts("Comment as") %> <%= current_user.default_pseud.name %>
diff --git a/config/initializers/gem-plugin_config/sanitizer_config.rb b/config/initializers/gem-plugin_config/sanitizer_config.rb
index 2106cce98e9..def9d78efa2 100644
--- a/config/initializers/gem-plugin_config/sanitizer_config.rb
+++ b/config/initializers/gem-plugin_config/sanitizer_config.rb
@@ -1,40 +1,39 @@
# Sanitize: http://github.com/rgrove/sanitize.git
class Sanitize
-
# This defines the configuration we use for HTML tags and attributes allowed in the archive.
module Config
ARCHIVE = freeze_config(
elements: %w[
a abbr acronym address b big blockquote br caption center cite code col
colgroup details figcaption figure dd del dfn div dl dt em h1 h2 h3 h4 h5 h6 hr
- i img ins kbd li ol p pre q s samp small span strike strong
+ i img ins kbd li ol p pre q rp rt ruby s samp small span strike strong
sub summary sup table tbody td tfoot th thead tr tt u ul var
],
attributes: {
- all: ['align', 'title', 'dir'],
- 'a' => ['href', 'name'],
- 'blockquote' => ['cite'],
- 'col' => ['span', 'width'],
- 'colgroup' => ['span', 'width'],
- 'hr' => ['align', 'width'],
- 'img' => ['align', 'alt', 'border', 'height', 'src', 'width'],
- 'ol' => ['start', 'type'],
- 'q' => ['cite'],
- 'table' => ['border', 'summary', 'width'],
- 'td' => ['abbr', 'axis', 'colspan', 'height', 'rowspan', 'width'],
- 'th' => ['abbr', 'axis', 'colspan', 'height', 'rowspan', 'scope', 'width'],
- 'ul' => ['type'],
+ all: %w[align title dir],
+ "a" => %w[href name],
+ "blockquote" => %w[cite],
+ "col" => %w[span width],
+ "colgroup" => %w[span width],
+ "hr" => %w[align width],
+ "img" => %w[align alt border height src width],
+ "ol" => %w[start type],
+ "q" => %w[cite],
+ "table" => %w[border summary width],
+ "td" => %w[abbr axis colspan height rowspan width],
+ "th" => %w[abbr axis colspan height rowspan scope width],
+ "ul" => %w[type]
},
add_attributes: {
- 'a' => {'rel' => 'nofollow'}
+ "a" => { "rel" => "nofollow" }
},
protocols: {
- 'a' => {'href' => ['ftp', 'http', 'https', 'mailto', :relative]},
- 'blockquote' => {'cite' => ['http', 'https', :relative]},
- 'img' => {'src' => ['http', 'https', :relative]},
- 'q' => {'cite' => ['http', 'https', :relative]}
+ "a" => { "href" => ["ftp", "http", "https", "mailto", :relative] },
+ "blockquote" => { "cite" => ["http", "https", :relative] },
+ "img" => { "src" => ["http", "https", :relative] },
+ "q" => { "cite" => ["http", "https", :relative] }
},
# TODO: This can be removed once we upgrade sanitizer gem, AO3-5801
@@ -45,7 +44,7 @@ module Config
CLASS_ATTRIBUTE = freeze_config(
# see in the Transformers section for what classes we strip
attributes: {
- all: ARCHIVE[:attributes][:all] + ['class']
+ all: ARCHIVE[:attributes][:all] + ["class"]
}
)
diff --git a/lib/paragraph_maker.rb b/lib/paragraph_maker.rb
index d0b4bf1b367..e8f583eef96 100644
--- a/lib/paragraph_maker.rb
+++ b/lib/paragraph_maker.rb
@@ -24,8 +24,8 @@ module ParagraphMaker
# Tags that need to go inside p tags
TAG_NAMES_TO_WRAP = (%w[
- a abbr acronym b big br cite code del dfn em i img ins kbd q s samp small
- span strike strong sub sup tt u var
+ a abbr acronym b big br cite code del dfn em i img ins kbd q rp rt ruby
+ s samp small span strike strong sub sup tt u var
] + INLINE_INVALID_TAGS).freeze
# Tags that can't be inside p tags
diff --git a/public/help/html-help.html b/public/help/html-help.html
index 976ff02f5c5..b11c5e6e26c 100644
--- a/public/help/html-help.html
+++ b/public/help/html-help.html
@@ -4,7 +4,7 @@ Allowed HTML
a, abbr, acronym, address, [align], [alt], [axis], b, big, blockquote, br, caption, center, cite, [class], code,
col, colgroup, dd, del, details, dfn, div, dl, dt, em, figcaption, figure, h1, h2, h3, h4, h5, h6, [height], hr, [href], i, img,
- ins, kbd, li, [name], ol, p, pre, q, s, samp, small, span, [src], strike, strong, sub, summary, sup, table, tbody, td,
+ ins, kbd, li, [name], ol, p, pre, q, rp, rt, ruby, s, samp, small, span, [src], strike, strong, sub, summary, sup, table, tbody, td,
tfoot, th, thead, [title], tr, tt, u, ul, var, [width]
diff --git a/spec/lib/html_cleaner_spec.rb b/spec/lib/html_cleaner_spec.rb
index 92b633e9de9..a9a9668d45a 100644
--- a/spec/lib/html_cleaner_spec.rb
+++ b/spec/lib/html_cleaner_spec.rb
@@ -486,6 +486,18 @@
end
end
end
+
+ ArchiveConfig.FIELDS_ALLOWING_HTML.each do |field|
+ it "preserves ruby-annotated HTML in #{field}" do
+ result = sanitize_value(field, "BigText")
+ expect(result).to include("BigText")
+ end
+
+ it "preserves ruby-annotated HTML without rp in #{field}" do
+ result = sanitize_value(field, "BigText")
+ expect(result).to include("BigText")
+ end
+ end
end
describe "fix_bad_characters" do
@@ -903,6 +915,12 @@
expect(doc.xpath("./p[3]").children.to_s.strip).to eq("yadda")
end
+ it "wraps ruby-annotated text in p tags" do
+ result = add_paragraphs_to_text("text with ルビ")
+ doc = Nokogiri::HTML.fragment(result)
+ expect(doc.xpath("./p[1]").children.to_s.strip).to eq("text with ルビ")
+ end
+
it "should keep attributes of block elements" do
result = add_paragraphs_to_text("some\n\ntext
")
doc = Nokogiri::HTML.fragment(result)
@@ -924,12 +942,24 @@
expect(doc.xpath("./p[contains(@class, 'bar')]").children.to_s.strip).to eq("foobar")
end
- it "should close unclosed tag within other tag" do
+ it "closes unclosed tag within other tag" do
html = "unclosed"
doc = Nokogiri::HTML.fragment(add_paragraphs_to_text(html))
expect(doc.xpath("./p/strong/em").children.to_s.strip).to eq("unclosed")
end
+ it "closes unclosed rt tags" do
+ html = "big text"
+ result = add_paragraphs_to_text(html)
+ expect(result).to include("big text")
+ end
+
+ it "closes unclosed rp tag" do
+ html = "big text"
+ result = add_paragraphs_to_text(html)
+ expect(result).to include("big text")
+ end
+
it "should re-nest mis-nested tags" do
html = "some text"
doc = Nokogiri::HTML.fragment(add_paragraphs_to_text(html))