How to ShowURL in Browser if URL contains a Pipe Character?

I need to open this URL with the user’s default browser: http://be.lehrplan.ch/index.php?code=b|7|2

1. ShowURL

Dim sURL As String = "http://be.lehrplan.ch/index.php?code=b|7|2" ShowURL(sURL)
Doesn’t work, because the Location in Safari will look like this: https://be.lehrplan.ch/index.php?code=b%257C7%257C2

2. AppleScript

Dim sURL As String = "http://be.lehrplan.ch/index.php?code=b|7|2" Dim sh As New Shell sh.execute "osascript -e 'open location """ + sURL + """'"
Doesn’t work, because the Location in Safari will look like this: https://be.lehrplan.ch/index.php?code=b%257C7%257C2

3. Declares

[code]Dim sURL As String = “http://be.lehrplan.ch/index.php?code=b|7|2
#if TargetMacOS and TargetCocoa then
Declare Function objc_getClass Lib “libobjc.dylib” ( name As CString ) As Ptr
Declare Function URLWithString Lib “Foundation” selector “URLWithString:” ( id As Ptr, URLString As CFStringRef ) As Ptr
Declare Function sharedWorkspace Lib “AppKit” selector “sharedWorkspace” ( obj As Ptr ) As Ptr
Declare Function openURL Lib “AppKit” selector “openURL:” ( obj As Ptr, url As Ptr ) As Boolean

Dim nsURL As Ptr = URLWithString(objc_getClass( “NSURL” ), sURL)

Dim workspace As Ptr = sharedWorkspace( objc_getClass( “NSWorkspace” ) )
call openURL( workspace, nsURL )

#endif[/code]
Doesn’t work because nsURL will be a NIL Pointer. It seems it can’t be instantiated with the given String.

ShowURL and AppleScript can be worked around by replacing “http” with “https”. But that doesn’t work for the Declare.
Let’s assume a user needs to open an URL with a Pipe from another location with no https - what to do? How can I reliably show any URL (containing a Pipe Character) in the user’s default web browser?

normally the “correct way” would be

http://be.lehrplan.ch/index.php?code=b%7C7%7C2"

but that doesn’t work for you either (I tried)… so it seems that the destination website is looking for a literal “|” and will not accept an encoded value. Note : the “|” is considered an unsafe character for use in URL

It sure seems like that. But that’s out of my control…

Ok, I can work around for this particular website. But I can’t know if our users will try to open URL’s with such a character on other websites/servers…

So i’m still trying to figure out a way to open the URL from a Xojo application. I can do it by manually entering the URL, so there may well be a "programmatic way"that I haven’t figured out yet…

I have it on good authority that there is literally no way to do what you’re asking on macOS. The system is always going to encode the parts (per an Xcode dev friend of mine).

You’re fighting with a documented standard to avoid fixing a poorly designed PHP script.
Fix the PHP script.

Wild goose chase. This Php is ill conceived.

A URL-encoded pipe character is %7C, not %257C. %25 is an encoded percent character, so I imagine this is the result of re-encoding and already encoded URL.

https://be.lehrplan.ch/index.php?code=b|7|2

[quote=389981:@Andrew Lambert]A URL-encoded pipe character is %7C, not %257C. %25 is an encoded percent character, so I imagine this is the result of re-encoding and already encoded URL.

https://be.lehrplan.ch/index.php?code=b|7|2[/quote]
interesting… when I tried that it did not work (see above)

I don’t have a mac or a recent edition of Xojo, but it works on Windows under Realstudio.

Because you’re trying to go to http not https, if you go to https it works.

https://be.lehrplan.ch/index.php?code=b|7|2

Their http to https redirector doesn’t like it without |'s

Yes. But since this is on a 3rd Party system, it’s out of my Control. So I have to deal with it. All I can try to “fix” is to inform them about it (but that doesn’t help if other domains/websites are doing the same) :slight_smile:

I guess it’s not the PHP on their Website that Needs to be fixed… it’s the redirection from http -> https (see below)

So to recap:
If we have to ShowURL with a Pipe character: it works just fine on Windows. However, on macOS:

On macOS, the URL always gets URLEncoded: | -> %7C

For the website mentioned, that works just fine if our users would link them to https.
If they save their links with http, then macOS will open the url: http…%7C
And their webserver will redirect to: https… and URLEncode again (% -> %25) -> that’s why we see %257C
And that obviously doesn’t work.

To sum up:
On Windows, we can ShowURL an URL that contains a Pipe Character. It doesn’t get URLEncoded by Xojo’s Framework or by the System.
On macOS, we can’t. The URL in the browser always ends up URLEncoded (at least according to Tim Parnell’s contacts). While in most cases that’s good, in this particular case it isn’t :wink: