parse wiki pages in migrations with HTML5

this matches the version used by Canvas proper when it
sanitizes user HTML, to prevent surprises in migrations

test plan:
 - put the HTML attached to the ticket in a page
 - it should survive an export/import or course copy round trip

flag = none
fixes LS-2241

Change-Id: Iae07c73e3b994dddf814ad5ee7dc4c2bd0284559
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/267889
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Nate Armstrong <narmstrong@instructure.com>
QA-Review: Nate Armstrong <narmstrong@instructure.com>
Product-Review: Jeremy Stanley <jeremy@instructure.com>
This commit is contained in:
Jeremy Stanley 2021-06-25 12:29:26 -06:00
parent cc4ead0bf5
commit 2244a69bcc
3 changed files with 10 additions and 5 deletions

View File

@ -95,6 +95,10 @@ module XMLHelper
File.exist?(path) ? ::Nokogiri::HTML(File.open(path)) : nil
end
def open_file_html5(path)
File.exist?(path) ? ::Nokogiri::HTML5(File.open(path)) : nil
end
def open_file_xml(path)
File.exist?(path) ? create_xml_doc(File.open(path)) : nil
end

View File

@ -27,7 +27,7 @@ module CC::Importer::Canvas
wiki_dir = @package_root.item_path(WIKI_FOLDER)
Dir["#{wiki_dir}/**/**"].each do |path|
next if File.directory?(path)
doc = open_file(path)
doc = open_file_html5(path)
wikis << convert_wiki(doc, path)
end

View File

@ -24,7 +24,7 @@ describe ContentMigration do
include_examples "course copy"
it "should copy wiki page attributes" do
page = @copy_from.wiki_pages.create!(:title => "title", :body => "<p>butter</p>",
page = @copy_from.wiki_pages.create!(:title => "title", :body => "<address><ul></ul></address>",
:editing_roles => "teachers", :todo_date => Time.zone.now)
run_course_copy
@ -33,6 +33,7 @@ describe ContentMigration do
attrs = [:title, :body, :editing_roles, :todo_date]
expect(page.attributes.slice(*attrs)).to eq page_to.attributes.slice(*attrs)
expect(page_to.body.strip).to eq "<address><ul></ul></address>"
end
it "should reset user on re-import" do