From 26cbdcf71a68d5515c91bf9cb4ec958ce90c2647 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 14 Jun 2019 18:49:04 +0100 Subject: [PATCH] Fix importing of GPX traces with a leading byte order marker Fixes #2258 --- lib/gpx.rb | 2 +- test/controllers/api/traces_controller_test.rb | 2 +- test/controllers/traces_controller_test.rb | 2 +- test/gpx/fixtures/b.gpx | 2 +- test/models/trace_test.rb | 13 ++++++++++++- 5 files changed, 16 insertions(+), 5 deletions(-) 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") -- 2.43.2