Decode URL in expression for View component

I am getting a tag which contains a URL which has been encoded or changed to the form with %xx, for example:

http%3a%2f%2ftestsitportal.johndoe.net%2fEWIPortal%2fPortalPage%2f%2fCEWIViewer.aspx

Is there a way to do an “expression” in a binding to make it where the Web Browser component in View can show the web page it is referring to?

There’s no direct expression function to use, but you can use the python built-in urllib to unescape a sanitized URL. You could put this into a runScript binding, either directly or by defining a simple helper function in a project/shared script.

If you want to use only an expression, replace method could accomplish this:

replace(replace("http%3a%2f%2ftestsitportal.johndoe.net%2fEWIPortal%2fPortalPage%2f%2fCEWIViewer.aspx", "%3a", ":"), "%2f", "/")
# output: http://testsitportal.johndoe.net/EWIPortal/PortalPage//CEWIViewer.aspx

Replace the first string in it with a reference to the tag.

The weakness of this method is you have to hard-code in the appropriate replacements for any escaping that may be required.

The replace is working for the moment, but I keep having to add new ones.

On the script, would it stay updated so that as the link changes the screen keeps changing? And where would this go?

Assuming you have a project script project.url with the following function defined:

def unescape(url):
    import urllib
    return urllib.unquote(url)

You would then construct a binding on your web browser component’s URL property as follows:
runScript('project.url.unescape', 0, {source/of/escaped/url})

Every time the source property changes (wherever you’re getting these sanitized URLs from), it will fire the binding, which will run the project script and return the human-readable URL to the web browser component.

2 Likes