# Not converting foo?a/b to foo?a%2fb

**URL:** https://discourse.gohugo.io/t/not-converting-foo-a-b-to-foo-a-2fb/16195
**Category:** support
**Created:** [January 7, 2019, 5:49am UTC](https://discourse.gohugo.io/t/not-converting-foo-a-b-to-foo-a-2fb/16195 "2019-01-07T05:49:22Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![vrdhn](https://avatars.discourse-cdn.com/v4/letter/v/e56c9b/32.png) [@vrdhn](https://discourse.gohugo.io/u/vrdhn)
#### Post date: [January 7, 2019, 5:49am UTC](https://discourse.gohugo.io/t/not-converting-foo-a-b-to-foo-a-2fb/16195/1 "2019-01-07T05:49:22Z")

</div>

Hi,  
I’m making a short code for linking to java doc.  
The with-frame java docs is a bit crazy, as it wants href to be `....?../.../` , and replacing / by %2f doesn’t work. ( e.g. [https://docs.oracle.com/javase/7/docs/api/index.html?java/lang/System.html](https://docs.oracle.com/javase/7/docs/api/index.html?java/lang/System.html) )

My shortcode is simply  
`<a href="https://docs.oracle.com/javase/7/docs/api/index.html?{{.Get 0}}"> {{.Inner}}</a>`  
And usage is  
`{{% ref "java/lang/System.html" %}} System {{% /ref %}}`  
This results in  
`<a href="https://docs.oracle.com/javase/7/docs/api/index.html?java%2flang%2fSystem.html"> System</a>`

I tried various functions in shortcode, but nothing generates the ‘/’ .

Now, the question is, how to make hugo emit ‘/’ instead of ‘%2f’, after it has seen the ‘?’ of href ?  
I’ld prefer to handle it in shortcode, rather than md,

–  
Regards

---

<div class="post-metadata">

### Author: ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)
#### Post date: [January 7, 2019, 3:43pm UTC](https://discourse.gohugo.io/t/not-converting-foo-a-b-to-foo-a-2fb/16195/2 "2019-01-07T15:43:50Z")

</div>

Try the piping your shortcode output to the `safeHTML` function.

> **[safeHTML](https://gohugo.io/functions/safehtml/)**
>
> Declares a provided string as a "safe" HTML document to avoid escaping by Go templates.

---

<div class="post-metadata">

### Author: ![vrdhn](https://avatars.discourse-cdn.com/v4/letter/v/e56c9b/32.png) [@vrdhn](https://discourse.gohugo.io/u/vrdhn)
#### Post date: [January 7, 2019, 4:16pm UTC](https://discourse.gohugo.io/t/not-converting-foo-a-b-to-foo-a-2fb/16195/3 "2019-01-07T16:16:11Z")

</div>

Unfortunately that still generates %2f for ‘/’

---

<div class="post-metadata">

### Author: ![moorereason](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/moorereason/32/592_2.png) [@moorereason](https://discourse.gohugo.io/u/moorereason)
#### Post date: [January 7, 2019, 4:26pm UTC](https://discourse.gohugo.io/t/not-converting-foo-a-b-to-foo-a-2fb/16195/4 "2019-01-07T16:26:26Z")

</div>

Go template security contexts can be tricky. Try generating the entire `href` attribute.

```auto
<a {{ printf "href=\"https://docs.oracle.com/javase/7/docs/api/index.html?%s\"" (.Get 0) | safeHTMLAttr }}>

```

_PS: Edited since I posted the wrong version of my comment. Too may tabs open!_
