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:
parent
cc4ead0bf5
commit
2244a69bcc
|
@ -37,7 +37,7 @@ module XMLHelper
|
|||
def get_node_val(node, selector, default=nil)
|
||||
node.at_css(selector) ? node.at_css(selector).text : default
|
||||
end
|
||||
|
||||
|
||||
# You can't do a css selector that only looks for direct
|
||||
# descendants of the current node, so you have to iterate
|
||||
# over the children and see if it's there.
|
||||
|
@ -88,13 +88,17 @@ module XMLHelper
|
|||
path = path.gsub('\\', '/') if path
|
||||
path
|
||||
end
|
||||
|
||||
|
||||
def open_file(path)
|
||||
# this is cheating; we use HTML because we don't deal properly with namespaces
|
||||
# even though it's really XML
|
||||
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
|
||||
|
@ -116,4 +120,4 @@ module XMLHelper
|
|||
doc
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue