Search code examples
javajsoup

Jsoup - test valid input body html with relative path


I have this code:

Whitelist whitelist = Whitelist.relaxed();
String test = "<a href=\"index.html?Proxy-Remote-User=ABC1\">"

With Jsoup if I run

Jsoup.isValid(test, whitelist)

It returns false. I think it's because of a missing protocol. Is there a way to make it acceptable?


Solution

  • Whitelist is deprecated, use Safelist instead. Your assumption is right, the protocol is the issue. I think you have to use a full url(with http or https specified). I got it working with this:

    test ="<a href=\"https:\\www.somesite\\index.html?Proxy-Remote-User=ABC1\">";
    System.out.println("Is valid:"+Jsoup.isValid(test, safelist));
    

    Output:

    Is valid:true