replacing special chars in url

Hi,

we've got a program which is called mega plus. This software is basically web based but it doesn'T use normal http protocol. Instead, it seperates parameters using the pipe | (%7c).

Sadly, this disturbs confluence. Links to megaplus don't work unless I manually repeace those pipes with %7c.

Is there any way to do this automatically?

3 answers

That is because the pipe character ('|') is not allowed in URLs. That is why it needs to be encoded. You can read more in the standard RFC 1738.

I am afraid there is not an easy way to replace those character automatically. There is already a feature request for this in https://jira.atlassian.com/browse/CONF-12818.

Some ugly user macro to the rescue smile

## @param Url:title=Url|type=string|required=true|desc=Server name (with protocol)
## @param Query:title=Query|type=string|required=true|desc=Query (to encode)
#set ($urlEncoderClass=$content.class.forName('java.net.URLEncoder'))
#set ($stringClass=$content.class.forName('java.lang.String'))
#set ($getInstanceMethod=$urlEncoderClass.getDeclaredMethod('encode', $stringClass))
#set ($encoded=$getInstanceMethod.invoke(null, $paramQuery))
<a href="$paramUrl${encoded}">$paramUrl$paramQuery</a>

Basically, in your case you can hardcode the paramUrl parameter to make it easier to put such links (only the query string to enter, which will be encoded properly in a link, but will look as-is in link's caption)

 

that'll help thank you laugh

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jul 10, 2018 in Confluence

We want to see the templates you've created in Confluence!

Hi Community, Jessica here from the Confluence Product Marketing team!  July’s community challenge is all about sharing pictures  — and as an extension of our first post on what ...

524 views 19 11
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you