I am building an tool that passes JSONs to a server. This JSON sometimes contains plus signs, for example in the form of a base64 encoded png. The JSON is stored in a database on the server side for later use. If I use a juce::URL for passing data to the server, the plus signs are replaced with spaces like this in juce_URL.cpp and it is thus not possible to decode the image.
String URL::removeEscapeChars (const String& s) { String result (s.replaceCharacter ('+', ' ')); // ... }
This is in compliance with standards and all, but poses a little issue for me. I seem to have a few solutions, all with a few drawbacks. The tool is internal only.
- Parse the JSON on the server side and replace spaces with plus signs. This will mean a lot of unpretty code on my side and the code is likely to be error prone. The structure and length of the JSON is not known up front.
- Do not use juce::URL and build the URL on my own. This is of course possible, but kinda defeats the purpose of the URL class. This may also be error prone.
- Just skip the replacing of plus signs above (i.e. replace with String result = s;). This actually works for my current JSONs, but it might have unknown side effects at a later stage. It could also become an issue when upgrading the Juce library later and then forgetting to perform this change again.
- Before decoding an image, just replace all spaces with a plus sign. This also works, but might have unknown side effects, although I cannot really think of anyone at this point.
Of these solutions, 3 and 4 seems best to me, but is there a better solution to this problem? I could not really find a way in the juce:URL class to skip the replacing of plus signs.