User macro fails after update from 7.4 to 7.13
Asked by NKS:

Hi

We used an own written macro with some velocity, some html, css and javascript. All worked well in version 7.4.7, but after the upgrade to 7.13.1 the macro does not work anymore. After a lot of debugging - I am not a developer - I am absolutely not able to find the reason. One problem is the javascript part: If I log the console output, it does what it should (set the display property of a div to block or hidden), but this change is not visible in the browser window - only the first occurency applies the change.

The other part is velocity itself. I created a simple macro to demonstrate the problem:

--------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------

## Params

## [@Param](/t5/user/viewprofilepage/user-id/1345631) otherpage:title=Link to another page\|type=confluence-content\|required=true\|desc=Link to another page  
## [@Param](/t5/user/viewprofilepage/user-id/1345631) pageinclude:title=Link to page to be included\|type=confluence-content\|required=true\|desc=Link to page to be included

## ------------------------------------------

\<h3\>set otherpage\</h3\>

#set( $linkotherpage = "\<ac:link\>\<ri:page ri:content-title='$paramotherpage' /\>\<ac:plain-text-link-body\>\<!\[CDATA\[Here goes the dummy text\]\]\>\</ac:plain-text-link-body\>\</ac:link\>" )

\<h3\>set includeline\</h3\>

#set ($includeline = "\<ri:page ri:content-title='$parampageinclude' /\>")

\<h3\>output other page from var\</h3\>

$linkotherpage

\<h3\>output direct to other page\</h3\>

\<ac:link\>\<ri:page ri:content-title='Testpage Link' /\>\<ac:plain-text-link-body\>\<!\[CDATA\[Here goes the dummy text\]\]\>\</ac:plain-text-link-body\>\</ac:link\>

\<h3\>include page direct\</h3\>

\<ac:structured-macro ac:name="include" ac:schema-version="1"\>\<ac:parameter ac:name=""\>\<ac:link\>\<ri:page ri:content-title="Testpage Include" /\>\</ac:link\>\</ac:parameter\>\</ac:structured-macro\>

\<h3\>include page from var\</h3\>  
\<ac:structured-macro ac:name="include" ac:schema-version="1"\>\<ac:parameter ac:name=""\>\<ac:link\>$includeline\</ac:link\>\</ac:parameter\>\</ac:structured-macro\>

---------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------

If the links are set directly, they work. If they are set from a variable, they don't work and I have absolutely no idea why. The macro above demonstrates the behavior.

Any help or idea would be really appreciated.

Thanks and regards

NKS


Answers:
author: Bill Bailey
body: My suggestion is to refresh your page, then check the logs to see what errors are logged at that time. Often, it will flag the issues to give you a chance at debug.

comments: author: NKS
body: Thank you for the suggestion, but there are no errors. There is nothing logged at all if I refresh the page.

I set the log level of velocity to DEBUG and made some tests. There are several lines, but they remain the same, no matter if my macro is on the page or not. So I assume, that there is no log output from my macro.

It seems that as soon as there are chars like \<, \>, :, aso, in the variable, the rendering of it doesen't work anymore. This happens even in safe mode.


author: Bill Bailey
body: I notice that your variables are offset with single qoutes, but then later, you where you are testing, you are surrounding the page name with double quotes.


author: NKS
body: Yes, you are right. But unfortunately, it makes no difference. When I pass the whole line into a variable, I have no choice beside using single quotes for the page name, as I am not able to escape double quotes (or I don't know how, because none of the ways I found online are working).

If I change the double quotes to single quotes - in the "direct testing" part - the result remains the same. So I assume for velocity it makes no difference if there are used single or double quotes.

I made some further thests: I can pass the $paramotherpage or $parampageinclude to other variables. As long as I don't use any special chars, it works. At least the velocity part.


author: Bill Bailey
body: Could you provide the rendered HTML, to see how the renderer is actually displaying the macro?


author: NKS
body: Sure, added as a jpeg. Thanks!

The page do be included contains the text "Diese Seite wird als Include angezeigt.".

![render.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/168942iC323D23B015745CB/image-size/large?v=v2&px=999 "render.jpg")


author: Bill Bailey
body: Your "include page from var" references the variable "$includelineor1" but I don't see where it is defined. I see where "$includeline" is set, but not the other.


author: NKS
body: Oh, yes, you are right. I just corrected this in the macro (also in my text above). The result itself does not change as the whole part, which is contained in "$includeline" ("\<ri:page ri:content-title='$parampageinclude' /\>") is not rendered. Therefore it includes the page itself where the macro is located at.


author: Bill Bailey
body: So when the macro fails to render, there is not a note in the log?

Why not structure this line:

```
<ac:structured-macro ac:name="include" ac:schema-version="1"><ac:parameter ac:name=""><ac:link>$includeline</ac:link></ac:parameter></ac:structured-macro>
```

To be the following instead?

```
<ac:structured-macro ac:name="include" ac:schema-version="1"><ac:parameter ac:name=""><ac:link><ri:page ri:content-title='$parampageinclude' /></ac:link></ac:parameter></ac:structured-macro>
```


author: NKS
body: Unfortunately not. Not a single line to this in the logs.

The whole macro would be much longer. There I split the page in two parts, if the page is in another space. So the construct of the link changes and therefore, I write the changing part in a variable. As it fails with the above example too, I did not mention it, because it would complicate the whole thing.

I think I will find other ways to achieve the goal, but in a more complicated and much longer way. I still don't know what changed that this does not work anymore. I even don't know if this only happens to me/us on our installation, or if it is the same behavior on all confluence installations (7.13.1 and above).


author: Bill Bailey
body: Unfortunately, Atlassian is not doing a great job supporting user macros, so there are no notifications when things change.

I would suggest trying to rebuild your macro starting with a blank page. Thier may some change in syntax that is hard to see.

Also, is there may be away to do this with java objects and methods, something like $page.getbodycontent (not sure that is correct, but you can search the API to find out for sure).


author: NKS
body: Thanks a lot for your help and your patience! For the velocity-part I found a solution. I just don't put the whole part of the link-code in the var, but just the page name or space name itself.

For the java script part - i just mentionned it but did not provide an example here - I found out that if the page (i.e. page A) with the macro is used as normal page, the javascript does not work correctly. If I include this page (page A) on another page (page B) and run the javascript on the other page (page B), it works as expected. So until I find a good solution, I just include the page (A) with the macro on another page (B) and it works. Somewhat special, but it is as it is...

Thanks again for your support!


author: Matthias Damsch
body: A bit late, but may be it helps other guys reading this thread...

The solution for this problem can be found [here](https://community.atlassian.com/t5/Confluence-questions/User-macro-fails-after-update-from-7-4-to-7-13/qaq-p/1857468). Confluence performs htmlencoding for every variable that is used as output, except the name of the variable ends with "Html". So in the discussed case here, name the variable "includelineHtml" instead of "includeline". That should work than.


Tags: confluence-server

server