How can I directly encode object for HTML using ESAPI.
String a = "<t"
String a= ESAPI.encoder().encodeForHTML(a);
Instead of String a, I want to pass a object which contains String fields?
How can I directly encode object for HTML using ESAPI.
String a = "<t"
String a= ESAPI.encoder().encodeForHTML(a);
Instead of String a, I want to pass a object which contains String fields?
You would have to write your own. Encoder.EncodeForHTML(String s )
will only take a string. ESAPI provides no other option to handle encoding for you.
You could use reflection to iterate over a class's String typed fields and encode them all. It sounds like you want to be able to generically just encode EVERYTHING without having to analyze what the application is doing with that data. That's risky for reasons I have previously outlined here.
You want to encode as late as possible, as close to the view as possible. It's the code in the view that determines the correct context for escaping.