Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Unescape CSS string escaped with Sightly context

boser87
Level 4
Level 4

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!

1 Accepted Solution
boser87
Correct answer by
Level 4
Level 4

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));

View solution in original post

1 Reply
boser87
Correct answer by
Level 4
Level 4

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));

View solution in original post