From: Tom Hughes Date: Fri, 14 Jun 2019 17:49:04 +0000 (+0100) Subject: Fix importing of GPX traces with a leading byte order marker X-Git-Tag: live~3118 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/26cbdcf71a68d5515c91bf9cb4ec958ce90c2647?ds=sidebyside;hp=-c Fix importing of GPX traces with a leading byte order marker Fixes #2258 --- 26cbdcf71a68d5515c91bf9cb4ec958ce90c2647 diff --git a/lib/gpx.rb b/lib/gpx.rb index 0aa23ae0b..1212db642 100644 --- a/lib/gpx.rb +++ b/lib/gpx.rb @@ -51,7 +51,7 @@ module GPX rescue Archive::Error io = ::File.open(@file) - case MimeMagic.by_magic(io).type + case MimeMagic.by_magic(io)&.type when "application/gzip" then io = Zlib::GzipReader.open(@file) when "application/x-bzip" then io = Bzip2::FFI::Reader.open(@file) end diff --git a/test/controllers/api/traces_controller_test.rb b/test/controllers/api/traces_controller_test.rb index 24ff6ee66..499fefbd7 100644 --- a/test/controllers/api/traces_controller_test.rb +++ b/test/controllers/api/traces_controller_test.rb @@ -153,7 +153,7 @@ module Api # And finally we should be able to do it with the owner of the trace basic_authorization anon_trace_file.user.display_name, "test" get :data, :params => { :id => anon_trace_file.id } - check_trace_data anon_trace_file, "66179ca44f1e93d8df62e2b88cbea732" + check_trace_data anon_trace_file, "db4cb5ed2d7d2b627b3b504296c4f701" end # Test downloading a trace that doesn't exist through the api diff --git a/test/controllers/traces_controller_test.rb b/test/controllers/traces_controller_test.rb index daa8a6787..84a655794 100644 --- a/test/controllers/traces_controller_test.rb +++ b/test/controllers/traces_controller_test.rb @@ -388,7 +388,7 @@ class TracesControllerTest < ActionController::TestCase # And finally we should be able to do it with the owner of the trace get :data, :params => { :display_name => anon_trace_file.user.display_name, :id => anon_trace_file.id }, :session => { :user => anon_trace_file.user } - check_trace_data anon_trace_file, "66179ca44f1e93d8df62e2b88cbea732" + check_trace_data anon_trace_file, "db4cb5ed2d7d2b627b3b504296c4f701" end # Test downloading a trace that doesn't exist diff --git a/test/gpx/fixtures/b.gpx b/test/gpx/fixtures/b.gpx index 44713988b..d69daa597 100644 --- a/test/gpx/fixtures/b.gpx +++ b/test/gpx/fixtures/b.gpx @@ -1,4 +1,4 @@ - + "b") + + trace.import + + assert_equal 1, trace.size + end + end + def test_import_handles_gz trace = create(:trace, :fixture => "d")