Antisamy converting single quotes to double quotes

401 views Asked by At

When i am trying to scan a html tag through antisammy, It gives weird output. It converts single quotes to double quotes.

CleanResults cr = as.scan(dirtyContent, policy);
System.out.println(cr.getCleanHTML());

Input string - <span style="font-family: 'times new roman', times, serif;">My name is Gourav</span>

Output string - <span style="font-family: &quot;times new roman&quot; , times , serif;">My name is Gourav</span>

So, as you can see, the single quotes are encoded as &quot; which when decoded gives " instead of '. This is causing problems for me.

Antisammy Version - 1.5.3

Policy File - antisamy-anythinggoes.xml

How can i solve this? Any help is appreciated

2

There are 2 answers

0
Gouravmoy Mohanty On BEST ANSWER

I raised this issue in the Antisammy GitHub project. This issue is now fixed :) . Please check the release notes for Release 1.7.1.

1
Hitesh Ghuge On

try this simple solution

try
{
    .
    .
    .
    dirtyContent.replaceAll("'", "SOME_COMBINATION_OF_CHARS");
    CleanResults cr = as.scan(dirtyContent, policy);
    dirtyContent.replaceAll("SOME_COMBINATION_OF_CHARS", "'");// here is your sanitised data 
}
catch(Exception ex)
{
    //do something on expn
}