5 Replies Latest reply on Mar 29, 2013 1:51 PM by Gary__F

    How to create a Java array for use with jsoup addAttributes() ?

    Gary__F Level 1

      Hi. Has anyone used jsoup for cleaning up user-submitted HTML?


      When I ask jsoup to add some extra attributes to its whitelist I get this error: "The addAttributes method was not found."


      The addAttributes() method requires an array. I tried using a CF array, a Java array, and even a string, but nothing worked.


      I'm using CF8. My test code is:


      <cfset jsoup = createObject("java","org.jsoup.Jsoup")>
      <cfset whitelist = CreateObject("java", "org.jsoup.safety.Whitelist")>
      <cfset html="<div style='font-size:24pt;'>This is BIG text</div>. This is an unwanted script: <script>alert('Boo!')</script>.<br>">
      <cfset myAttribsArray=[":all","style"]>
      <cfset myAttribsArray=javacast("string[]", myAttribsArray)>
      <cfset sanitized = jsoup.clean(html, Whitelist.relaxed().addAttributes(myAttribsArray))>
      <textarea rows="10" cols="60"> #HtmlEditFormat(sanitized)#</textarea>


      The code works if I don't bother with addAttributes(), but I need to add the style attribute to the whitelist. Can anyone help please? Thanks.


      The API reference for addAttributes() is here: