From 4c05df590a4fd3a99806b6ce65c2a305cac4f0a7 Mon Sep 17 00:00:00 2001 From: Ronald Brill Date: Mon, 3 Jun 2024 19:34:34 +0200 Subject: [PATCH] trim namespace prefix (issue #114) --- .../cyberneko/html/dom/HTMLDocumentImpl.java | 12 ++++++++++-- .../canonical/test082.html.canonical-domhtml | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/htmlunit/cyberneko/html/dom/HTMLDocumentImpl.java b/src/main/java/org/htmlunit/cyberneko/html/dom/HTMLDocumentImpl.java index de2f6e05..0560fe53 100644 --- a/src/main/java/org/htmlunit/cyberneko/html/dom/HTMLDocumentImpl.java +++ b/src/main/java/org/htmlunit/cyberneko/html/dom/HTMLDocumentImpl.java @@ -503,10 +503,18 @@ public Element createElementNS(final String namespaceURI, final String qualified @Override public Element createElementNS(final String namespaceURI, final String qualifiedname) { if (namespaceURI == null - || namespaceURI.length() == 0 - || NamespaceBinder.XHTML_1_0_URI.equals(namespaceURI)) { + || namespaceURI.length() == 0) { return createElement(qualifiedname); } + + if (NamespaceBinder.XHTML_1_0_URI.equals(namespaceURI)) { + final int index = qualifiedname.indexOf(':'); + if (index != -1) { + return createElement(qualifiedname.substring(index + 1)); + } + return createElement(qualifiedname); + } + return super.createElementNS(namespaceURI, qualifiedname); } diff --git a/src/test/resources/org/htmlunit/cyberneko/testfiles/canonical/test082.html.canonical-domhtml b/src/test/resources/org/htmlunit/cyberneko/testfiles/canonical/test082.html.canonical-domhtml index d2d4b35d..8b7bc00b 100644 --- a/src/test/resources/org/htmlunit/cyberneko/testfiles/canonical/test082.html.canonical-domhtml +++ b/src/test/resources/org/htmlunit/cyberneko/testfiles/canonical/test082.html.canonical-domhtml @@ -1,7 +1,7 @@ (HTML (HEAD )HEAD -(H:BODY +(BODY A{http://www.w3.org/2000/xmlns/}xmlns:h http://www.w3.org/1999/xhtml -)H:BODY +)BODY )HTML