URL::addEscapeChars does not generate URLs that open


#1

I’m trying to convert a string with URL::addEscapeChars and then call WebBrowserComponent::goToURL to open the URL. The problem is, the URL::addEscapeChars is escaping such normal things as slashes and colons. I have to be honest, I’m not certain what is technically in spec, but I can speak from experience and say that the string being output by addEscapeChars does not resolve correctly using the OSX WebBrowserComponent:

The following code:

    String s = "file://My Path With Spaces In it/andAlsoSlashes.html";
    LOG_DEBUG("%s%s", s.toUTF8(), "\n");
    s = URL::addEscapeChars(s, false);  // tried this with both true and false
    LOG_DEBUG("%s%s", s.toUTF8(), "\n");
    browser->goToURL(s);

Outputs the following on my machine:

[14:16:30] file://My Path With Spaces In it/andAlsoSlashes.html
[14:16:30] file%3a%2f%2fMy%20Path%20With%20Spaces%20In%20it%2fandAlsoSlashes.html

I was hoping it would output:

[14:16:30] file://My Path With Spaces In it/andAlsoSlashes.html
[14:16:30] file://My%20Path%20With%20Spaces%20In%20it/andAlsoSlashes.html

As I said, the string being returned to me now will not open in a WebBrowserComponent, whereas the the one that I was hoping for does.

Do I misunderstand the use of the URL::addEscapeChars()? Am I doing something dumb here? thanks in advance for any help


#2

As far as I can tell JUCE is doing what it’s suppoased to here. But it’s still not doing what I want it to… which is return a string that will resolve to an actual file. Any suggestions on how to do this?

Thanks,

*m


#3

the method you are using should be used on the actual URL, not the protocol specifier, this is a handy utility not a “cleanup my url” kind of utility. seperate the “file://” from the rest and apply the method only on the rest. you should be fine.


#4

It didn’t work, but I just used the string::replace function to clean up only the spaces and that seems to work. Not sure yet if it’s just the way the OSX libraries work or if it will be the same for windows.

On OSX, the WebBrowserComponent chokes on spaces, but doesn’t like it when ‘/’ or ‘+’ (which also happens to be in my path) were escaped. Go figure.


#5

This may help, but it’s not the right way to do it
http://www.rawmaterialsoftware.com/juceforum/viewtopic.php?p=22405&highlight=#22405