Properly import files with upper-case extensions (#5493)

* Properly import files with upper-case extensions

Signed-off-by: Alexander Borsuk <me@alex.bio>
This commit is contained in:
Alexander Borsuk 2023-07-09 15:19:46 +02:00 committed by GitHub
parent a4d1399c0e
commit c01a1a6fa3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 18 deletions

View file

@ -608,35 +608,70 @@
<data android:mimeType="*/*"/>
<!-- See http://stackoverflow.com/questions/3400072/pathpattern-to-match-file-extension-does-not-work-if-a-period-exists-elsewhere-i -->
<data android:pathPattern="/.*\\.kmz" />
<data android:pathPattern="/.*\\.KMZ" />
<data android:pathPattern="/.*\\..*\\.kmz" />
<data android:pathPattern="/.*\\..*\\.KMZ" />
<data android:pathPattern="/.*\\..*\\..*\\.kmz" />
<data android:pathPattern="/.*\\..*\\..*\\.KMZ" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\.kmz" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\.KMZ" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\.kmz" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\.KMZ" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\.kmz" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\.KMZ" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\..*\\.kmz" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\..*\\.KMZ" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.kmz" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.KMZ" />
<data android:pathPattern="/.*\\.kml" />
<data android:pathPattern="/.*\\.KML" />
<data android:pathPattern="/.*\\..*\\.kml" />
<data android:pathPattern="/.*\\..*\\.KML" />
<data android:pathPattern="/.*\\..*\\..*\\.kml" />
<data android:pathPattern="/.*\\..*\\..*\\.KML" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\.kml" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\.KML" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\.kml" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\.KML" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\.kml" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\.KML" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\..*\\.kml" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\..*\\.KML" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.kml" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.KML" />
<data android:pathPattern="/.*\\.gpx" />
<data android:pathPattern="/.*\\.GPX" />
<data android:pathPattern="/.*\\..*\\.gpx" />
<data android:pathPattern="/.*\\..*\\.GPX" />
<data android:pathPattern="/.*\\..*\\..*\\.gpx" />
<data android:pathPattern="/.*\\..*\\..*\\.GPX" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\.gpx" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\.GPX" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\.gpx" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\.GPX" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\.gpx" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\.GPX" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpx" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\..*\\.GPX" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpx" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.GPX" />
<!-- Old MAPS.ME binary format //-->
<data android:pathPattern="/.*\\.kmb" />
<data android:pathPattern="/.*\\.KMB" />
<data android:pathPattern="/.*\\..*\\.kmb" />
<data android:pathPattern="/.*\\..*\\.KMB" />
<data android:pathPattern="/.*\\..*\\..*\\.kmb" />
<data android:pathPattern="/.*\\..*\\..*\\.KMB" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\.kmb" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\.KMB" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\.kmb" />
<data android:pathPattern="/.*\\.gpx" />
<data android:pathPattern="/.*\\..*\\.gpx" />
<data android:pathPattern="/.*\\..*\\..*\\.gpx" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\.gpx" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\.gpx" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\.gpx" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpx" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpx" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\.KMB" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\.kmb" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\.KMB" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\..*\\.kmb" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\..*\\.KMB" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.kmb" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.KMB" />
</intent-filter>
</activity>

View file

@ -444,10 +444,11 @@ public enum BookmarkManager
// See IsBadCharForPath()
filename = filename.replaceAll("[:/\\\\<>\"|?*]", "");
final String lowerCaseFilename = filename.toLowerCase(java.util.Locale.ROOT);
// Check that filename contains bookmarks extension.
for (String ext: BOOKMARKS_EXTENSIONS)
{
if (filename.endsWith(ext))
if (lowerCaseFilename.endsWith(ext))
return filename;
}

View file

@ -206,12 +206,6 @@ void ValidateKmlData(std::unique_ptr<kml::FileData> & data)
}
}
// Returns extension with a dot in a lower case.
std::string GetFileExt(std::string const & filePath)
{
return strings::MakeLowerCase(base::GetFileExtension(filePath));
}
bool IsBadCharForPath(strings::UniChar c)
{
if (c < ' ')
@ -245,6 +239,11 @@ std::string RemoveInvalidSymbols(std::string const & name)
return strings::ToUtf8(filtered);
}
// Returns extension with a dot in a lower case.
std::string GetLowercaseFileExt(std::string const & filePath)
{
return strings::MakeLowerCase(base::GetFileExtension(filePath));
}
std::string GenerateUniqueFileName(std::string const & path, std::string name, std::string_view ext)
{
@ -339,7 +338,7 @@ std::unique_ptr<kml::FileData> LoadKmlFile(std::string const & file, KmlFileType
std::string GetKMLPath(std::string const & filePath)
{
std::string const fileExt = GetFileExt(filePath);
std::string const fileExt = GetLowercaseFileExt(filePath);
std::string fileSavePath;
if (fileExt == kKmlExtension || fileExt == kGpxExtension)
{
@ -367,7 +366,7 @@ std::string GetKMLPath(std::string const & filePath)
std::string ext;
for (size_t i = 0; i < files.size(); ++i)
{
ext = GetFileExt(files[i].first);
ext = GetLowercaseFileExt(files[i].first);
if (ext == kKmlExtension)
{
kmlFileName = files[i].first;

View file

@ -103,6 +103,7 @@ std::unique_ptr<kml::FileData> LoadKmlFile(std::string const & file, KmlFileType
std::unique_ptr<kml::FileData> LoadKmlData(Reader const & reader, KmlFileType fileType);
std::string GetKMLPath(std::string const & filePath);
std::string GetLowercaseFileExt(std::string const & filePath);
bool SaveKmlFileSafe(kml::FileData & kmlData, std::string const & file, KmlFileType fileType);
bool SaveKmlData(kml::FileData & kmlData, Writer & writer, KmlFileType fileType);

View file

@ -1871,7 +1871,7 @@ void BookmarkManager::LoadBookmarkRoutine(std::string const & filePath, bool isT
std::string fileSavePath = GetKMLPath(filePath);
if (!fileSavePath.empty())
{
auto const ext = base::GetFileExtension(filePath);
auto const ext = GetLowercaseFileExt(filePath);
std::unique_ptr<kml::FileData> kmlData;
if (ext == ".kml" || ext == ".kmz")
kmlData = LoadKmlFile(fileSavePath, KmlFileType::Text);