alexboia / WP-Trip-Summary

A WordPress trip summary plugin to help travel bloggers manage and display structured information about their train rides and biking or hiking trips
BSD 3-Clause "New" or "Revised" License
13 stars 4 forks source link

GPX track files encoded as UTF-8 with BOM are not processed and issue an error when uploaded #52

Closed alexboia closed 4 years ago

alexboia commented 4 years ago

Describe the bug Issue started on the plug-in's WP directory support page: https://wordpress.org/support/topic/donload-gpx-file/. The issue is that GPX files that are encoded with a byte order mark (BOM) are not correctly validated by the plug-in and, thus, rejected with an error.

To Reproduce Steps to reproduce the behavior:

  1. Go to 'Edit trip summary' -> 'Map'
  2. Click on the upload button
  3. Select a GPX track file that is encoded as UTF-8 with BOM
  4. See error

Expected behavior The GPX track file is correctly uploaded and processed.

Desktop (please complete the following information): Regardless of client desktop/browser configuration.

alexboia commented 4 years ago

The issue is mainly caused by the MimeReader library used to sniff mime types: it does not support sniffing XML files with BOM: if it sees a BOM, it automatically issues the text/plain mime type. So the fix is centered around: a) supporting XML files that have a BOM in their header; b) prioritizing sniffing XML files with BOM over plain text files with BOM.