Search code examples
springspecial-charactersexpression-evaluation

spring evaluate expression (SpEL), how can I force it to not interprete some specials characteres


I'm using spring tool SpEL to evaluate some expressions.

The expression contain HTML/css programatically generated and some variables to evaluate.

<span style='font-family: 'Comic Sans MS';>TOTAL HT &nbsp; = totalItem  </span>

where totalItem is a member of an object Item;

Partial example :

Item item = new Item ("item", 1658);
String s = "<span style='font-family: 'Comic Sans MS';>TOTAL HT &nbsp; = totalItem </span>";
StandardEvaluationContext itemContext = new StandardEvaluationContext(item);
Expression exp = parser.parseExpression(s);
s2 = exp.getValue(itemContext, String.class);

The problem is that SpEL interpret all " ' " and all " ; ".

So I'm looking for a way to force SpEl to interprete only the special caractere that I want to.


Solution

  • You should escape those characters instead of interpreting them.

    for ', escape them like '' And you can just leave ; as it is.