The parser will allow an ampersand in the title tag but fails in some instances. The following will cause it to treat all HTML that follows as plain text:
String htmlCode = "<html><head><title>&X</title></head</html>";
System.out.println(page.getTitleText());
prints &x</title></head</html> instead of &x.
The full code to reproduce:
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.StringWebResponse;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HTMLParser;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
public class HtmlUnitTest {
public static void main(String[] args) {
String htmlCode = "<html><head><title>&x</title></head</html>";
try (WebClient webClient = new WebClient(BrowserVersion.BEST_SUPPORTED)) {
StringWebResponse response = new StringWebResponse(htmlCode, new URL("http://http://htmlunit.sourceforge.net//test.html"));
HtmlPage page = HTMLParser.parseHtml(response, webClient.getCurrentWindow());
System.out.println(page.getTitleText());
// work with the html page
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
The parser will allow an ampersand in the title tag but fails in some instances. The following will cause it to treat all HTML that follows as plain text:
String htmlCode = "<html><head><title>&X</title></head</html>";System.out.println(page.getTitleText());prints
&x</title></head</html>instead of&x.The full code to reproduce: