From 85ec71d6e4f9ced23be1de8fdbc9349c338e3525 Mon Sep 17 00:00:00 2001 From: hogliux Date: Tue, 13 Nov 2018 16:26:31 +0000 Subject: [PATCH] Fixed an issue where file URIs on Windows would not be parsed correctly --- modules/juce_core/network/juce_URL.cpp | 23 ++++++++++++++--------- modules/juce_core/network/juce_URL.h | 1 + 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/modules/juce_core/network/juce_URL.cpp b/modules/juce_core/network/juce_URL.cpp index dcb232a301..fc9709848a 100644 --- a/modules/juce_core/network/juce_URL.cpp +++ b/modules/juce_core/network/juce_URL.cpp @@ -343,14 +343,7 @@ bool URL::isWellFormed() const String URL::getDomain() const { - auto start = URLHelpers::findStartOfNetLocation (url); - auto end1 = url.indexOfChar (start, '/'); - auto end2 = url.indexOfChar (start, ':'); - - auto end = (end1 < 0 && end2 < 0) ? std::numeric_limits::max() - : ((end1 < 0 || end2 < 0) ? jmax (end1, end2) - : jmin (end1, end2)); - return url.substring (start, end); + return getDomainInternal (false); } String URL::getSubPath() const @@ -391,7 +384,7 @@ File URL::fileFromFileSchemeURL (const URL& fileURL) return {}; } - auto path = removeEscapeChars (fileURL.getDomain()).replace ("+", "%2B"); + auto path = removeEscapeChars (fileURL.getDomainInternal (true)).replace ("+", "%2B"); #ifdef JUCE_WINDOWS bool isUncPath = (! fileURL.url.startsWith ("file:///")); @@ -529,6 +522,18 @@ bool URL::isProbablyAnEmailAddress (const String& possibleEmailAddress) && ! possibleEmailAddress.endsWithChar ('.'); } +String URL::getDomainInternal (bool ignorePort) const +{ + auto start = URLHelpers::findStartOfNetLocation (url); + auto end1 = url.indexOfChar (start, '/'); + auto end2 = ignorePort ? -1 : url.indexOfChar (start, ':'); + + auto end = (end1 < 0 && end2 < 0) ? std::numeric_limits::max() + : ((end1 < 0 || end2 < 0) ? jmax (end1, end2) + : jmin (end1, end2)); + return url.substring (start, end); +} + #if JUCE_IOS URL::Bookmark::Bookmark (void* bookmarkToUse) : data (bookmarkToUse) diff --git a/modules/juce_core/network/juce_URL.h b/modules/juce_core/network/juce_URL.h index b2ad893048..82e57829f0 100644 --- a/modules/juce_core/network/juce_URL.h +++ b/modules/juce_core/network/juce_URL.h @@ -526,6 +526,7 @@ private: StringArray parameterNames, parameterValues; static File fileFromFileSchemeURL (const URL&); + String getDomainInternal (bool) const; struct Upload : public ReferenceCountedObject {