Browse Source

Added an option to escape round brackets in URLs

tags/2021-05-28
hogliux 9 years ago
parent
commit
ae13dd6d6c
2 changed files with 13 additions and 5 deletions
  1. +7
    -4
      modules/juce_core/network/juce_URL.cpp
  2. +6
    -1
      modules/juce_core/network/juce_URL.h

+ 7
- 4
modules/juce_core/network/juce_URL.cpp View File

@@ -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<char> 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]);


+ 6
- 1
modules/juce_core/network/juce_URL.h View File

@@ -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.


Loading…
Cancel
Save