diff --git a/app/models/content_migration.rb b/app/models/content_migration.rb index 2a7960c48c0..09ed991357f 100644 --- a/app/models/content_migration.rb +++ b/app/models/content_migration.rb @@ -313,8 +313,7 @@ class ContentMigration < ActiveRecord::Base @zip_file = Zip::ZipFile.open(@exported_data_zip.path) @exported_data_zip.close data = JSON.parse(@zip_file.read('course_export.json'), :max_nesting => 50) - data = data.with_indifferent_access if data.is_a? Hash - data['all_files_export'] ||= {} + data = prepare_data(data) if @zip_file.find_entry('all_files.zip') # the file importer needs an actual file to process @@ -342,6 +341,13 @@ class ContentMigration < ActiveRecord::Base end handle_asynchronously :import_content, :priority => Delayed::LOW_PRIORITY, :max_attempts => 1 + def prepare_data(data) + data = data.with_indifferent_access if data.is_a? Hash + TextHelper.recursively_strip_invalid_utf8!(data, true) if RUBY_VERSION >= "1.9" + data['all_files_export'] ||= {} + data + end + def copy_options self.migration_settings[:copy_options] end diff --git a/spec/models/content_migration_spec.rb b/spec/models/content_migration_spec.rb index c7519fcbada..fbbf3d99ee6 100644 --- a/spec/models/content_migration_spec.rb +++ b/spec/models/content_migration_spec.rb @@ -1616,6 +1616,18 @@ equation: [{ + 'question_name' => "hai\xfbabcd" + }] + } + ContentMigration.new.prepare_data(data)[:assessment_questions][0][:question_name].should == "haiabcd" + end + end + context "import_object?" do before do @cm = ContentMigration.new