Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How can I avoid html encoding for Parameters in user macros

Michael Ammann December 14, 2020

We have a user macro with a parameter of type confluence-content. When we try to get the page with a title containing special characters e.g. "This & That", the parameter returns the title encoded "This & That". So when trying to get the page from the pageManager, the page is not found. Is there a possibility to avoid the encoding of a parameter?

1 answer

1 vote
Bill Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 14, 2020

is your parameter type set to "type=confluence-content"? That is supposed to allow a user to run a match to existing content.

Michael Ammann December 16, 2020

Yes, it is set to confluence-content. In a macro within a plugin, this parameter then is returned without encoding but in a user macro when rendering the velocity template, the parameter will be encoded.

Bill Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2020

Can you convert the results from the PageManager to encoded HTML before doing a compare? Or are you trying to do a page look up?

And how about just pulling the pageID of the desired page?

Bill Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2020

The other way is to parse your parameter to find replace HTML encodings. Not fun, but you can add corner cases (and tell user to please not put special characters in page names).

Michael Ammann December 17, 2020

When using the confluence-content type for a parameter, only "spaceKey:pageTitle" is available for rendering the velocity template. I replaced the known entities now, but this is not generic and I didn't found a decoder, which is available in the rendering context and no way to avoid the encoding of the parameter.

Bill Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 17, 2020

I have never used that parameter type, but there are others that don't work the way you think they would. User macros are in need of TLC for quite some time. It is a shame, but they are not maintaining this very powerful tool, and given the forced move to the cloud, user macros will only be available to data center customers -- larger entities that have resources to program full-blown plugins.

Bill Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 29, 2020

@Michael AmmannI found this article when researching another topic:

how-to-display-modified-page-dates-in-a-table 

What is interesting is that they are using the confluence content type in a user macro and converting it back into a page object. I think that will solve your problem as once it is an objects, the usual methods can be used.

Let me know if this helps

Like Simon Tost _TNG_ likes this
Michael Ammann January 11, 2021

In our macro we make quite the same as mentioned in this article. But as the link contains the page title, we have the problem that the title is escaped and e.g. the & is replaced by the html entity & If there is no way to avoid this conversion, the page tile has to be decoded again and I found no velocity helper to do this for all cases.

Bill Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 11, 2021

I think the issue is having page names that include the following reserved characters: ", ', <,>,&.

My suggestion is to build a find/replace function for those five characters.

Like Simon Tost _TNG_ likes this
Michael Ammann January 13, 2021

As workaround I already replaced the &amp; with the & and I will enhance that. I tried to find a more common solution but I found none. 

Like Simon Tost _TNG_ likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
7.4.6
TAGS
AUG Leaders

Atlassian Community Events