From 79b8b4fe18cceceea420f76fbaf3fc0e198cad2b Mon Sep 17 00:00:00 2001 From: cbasguti Date: Mon, 29 May 2023 16:22:14 +0200 Subject: [PATCH] dev: serializing unparented node on java --- .../internals/SaveContextVisitor.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/ext/java/nokogiri/internals/SaveContextVisitor.java b/ext/java/nokogiri/internals/SaveContextVisitor.java index a1ccc348d9b..9c5f2f55ef6 100644 --- a/ext/java/nokogiri/internals/SaveContextVisitor.java +++ b/ext/java/nokogiri/internals/SaveContextVisitor.java @@ -807,17 +807,26 @@ public int compare(Attr attr0, Attr attr1) { // no-op } - private boolean - isHtmlScript(Text text) - { - return htmlDoc && text.getParentNode().getNodeName().equals("script"); + private boolean isHtmlScript(Text text) { + Node parentNode = text.getParentNode(); + if (parentNode != null && parentNode.getNodeName().equals("script")) { + return htmlDoc; + } else { + System.out.println("getParentNode() returned null or parent node is not 'script'."); + return false; + } } - - private boolean - isHtmlStyle(Text text) - { - return htmlDoc && text.getParentNode().getNodeName().equals("style"); + + private boolean isHtmlStyle(Text text) { + Node parentNode = text.getParentNode(); + if (parentNode != null && parentNode.getNodeName().equals("style")) { + return htmlDoc; + } else { + System.out.println("getParentNode() returned null or parent node is not 'style'."); + return false; + } } + public boolean enter(Text text)