Convert String to URL in vm file.

Hi All,

I want to convert a plain String to a URL(clickable link) in a vm file. I have tried using $link.encode(String) but it takes as a literal. That is , it just prints "$link.encode(String)", doesnt encode. I am not sure what do I have to enable and where in jira. Please suggest. We are using jira 6.0.8 currently which will be upgraded shortly to the latest version.

Thanks,

Hemanth

1 answer

Hi! :)

Have you tried this one:

ib.name

Escapes the characters in a String to be suitable to use as an HTTP parameter value.

String url(Object string)
<dl><dt>Parameters</dt><dd><dl><dt>string</dt><dd>the string to escape values, may be null.</dd></dl></dd></dl><dl><dt>Returns</dt><dd>a new escaped String, null if null string input</dd></dl>

Delegates the process to java.net.URLEncoder#encodeURL(String,"UTF-8").

If $url had the following value:

Hello here & there

then the following Velocity script:

$esc.url($url)

produces this output:

hello+here+%26+there

Source: http://velocity.apache.org/tools/devel/generic/EscapeTool.html#url()

The other option would be ( https://velocity.apache.org/tools/devel/velocity-tools-generic/apidocs/org/apache/velocity/tools/ConversionUtils.html#toURL(java.lang.String) ):

toURL

public static URL toURL(String value)
<dl><dd>Converts a string to a URL. It will first try to treat the string as a File name, then a classpath resource, then finally as a literal URL. If none of these work, then this will return null.

</dd><dd><dl><dt>Parameters:</dt><dd>value - - the string to parse</dd><dt>Returns:</dt><dd>the URL form of the string or null</dd><dt>See Also:</dt><dd>File, ClassUtils.getResource(String,Object), URL</dd><dd></dd><dd></dd></dl></dd></dl>

I'm trying the following in a macro:

$esc.url($url)

However, I just see the same output: $esc.url($url)

Any assistance would be appreciated

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Wednesday in Jira

Make your Atlassian Cloud products more secure: our NEW admin security guide

Hey admins! I’m Dave, Principal Product Manager here at Atlassian working on our cloud platform and security products. Cloud security is a moving target. As you adopt more products, employees consta...

442 views 0 9
Read article

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