From ae13dd6d6c59ca8265b48b330ea371741f9cb746 Mon Sep 17 00:00:00 2001 From: hogliux Date: Thu, 27 Oct 2016 18:35:30 +0100 Subject: [PATCH] Added an option to escape round brackets in URLs --- modules/juce_core/network/juce_URL.cpp | 11 +++++++---- modules/juce_core/network/juce_URL.h | 7 ++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/modules/juce_core/network/juce_URL.cpp b/modules/juce_core/network/juce_URL.cpp index 46b1d3cf04..4c34bda68a 100644 --- a/modules/juce_core/network/juce_URL.cpp +++ b/modules/juce_core/network/juce_URL.cpp @@ -496,10 +496,13 @@ String URL::removeEscapeChars (const String& s) return String::fromUTF8 (utf8.getRawDataPointer(), utf8.size()); } -String URL::addEscapeChars (const String& s, const bool isParameter) +String URL::addEscapeChars (const String& s, const bool isParameter, bool roundBracketsAreLegal) { - const CharPointer_UTF8 legalChars (isParameter ? "_-.*!'()" - : ",$_-.*!'()"); + String legalChars (isParameter ? "_-.*!'" + : ",$_-.*!'"); + + if (roundBracketsAreLegal) + legalChars += "()"; Array utf8 (s.toRawUTF8(), (int) s.getNumBytesAsUTF8()); @@ -508,7 +511,7 @@ String URL::addEscapeChars (const String& s, const bool isParameter) const char c = utf8.getUnchecked(i); if (! (CharacterFunctions::isLetterOrDigit (c) - || legalChars.indexOf ((juce_wchar) c) >= 0)) + || legalChars.containsChar ((juce_wchar) c))) { utf8.set (i, '%'); utf8.insert (++i, "0123456789ABCDEF" [((uint8) c) >> 4]); diff --git a/modules/juce_core/network/juce_URL.h b/modules/juce_core/network/juce_URL.h index c68afe16ee..33755eab46 100644 --- a/modules/juce_core/network/juce_URL.h +++ b/modules/juce_core/network/juce_URL.h @@ -379,10 +379,15 @@ public: as a parameter, so it also encodes '$' and ',' (which would otherwise be legal in a URL. + @param roundBracketsAreLegal Technically round brackets are ok in URLs, + however, some servers (like AWS) also want + round brackets to be escaped. + @see removeEscapeChars */ static String addEscapeChars (const String& stringToAddEscapeCharsTo, - bool isParameter); + bool isParameter, + bool roundBracketsAreLegal = true); /** Replaces any escape character sequences in a string with their original character codes.