Hi,
I need to unescape (and then escape again) a string result of using Sightly context "styleString":
a string example is background-image: url(\2f content\2f dam\2fwebsites\2fglobal\2fimages-2\2f 2018\2f 05\2fKoala.jpg);
I need to unescape the String in Java and then escape it again. StringEscapeUtils does not seem to work in this case. Do you know how can I escape/unescape strings result of Sightly's styleString encoding?
Thanks!
Solved! Go to Solution.
Views
Replies
Total Likes
I found the way to solve the problem. I am using XSSAPI https://sling.apache.org/apidocs/sling9/org/apache/sling/xss/XSSAPI.html encodeForCSSString method which is used by AEM internally for encoding sensitive parts of the HTML page through 'context' option in HTL. I am encoding both ends of my comparison so I don’t actually need to decode.
And if you are wondering how to unit test a Sling Model that has that kind of dependency, this is how you add the mocked class to your test context:
context.registerService(XSSAPI.class, Mockito.mock(XSSAPI.class));
Views
Replies
Total Likes
I found the way to solve the problem. I am using XSSAPI https://sling.apache.org/apidocs/sling9/org/apache/sling/xss/XSSAPI.html encodeForCSSString method which is used by AEM internally for encoding sensitive parts of the HTML page through 'context' option in HTL. I am encoding both ends of my comparison so I don’t actually need to decode.
And if you are wondering how to unit test a Sling Model that has that kind of dependency, this is how you add the mocked class to your test context:
context.registerService(XSSAPI.class, Mockito.mock(XSSAPI.class));
Views
Replies
Total Likes