From 31a4121565369512d2fb265c9194b318621cbcd0 Mon Sep 17 00:00:00 2001 From: Young242 Date: Sat, 21 Dec 2024 13:57:47 +0800 Subject: [PATCH] fix pretty print in Declaration --- .../org/jxmpp/xml/splitter/XmlPrettyPrinter.java | 5 +++++ .../org/jxmpp/xml/splitter/XmlPrettyPrinterTest.java | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/jxmpp-core/src/main/java/org/jxmpp/xml/splitter/XmlPrettyPrinter.java b/jxmpp-core/src/main/java/org/jxmpp/xml/splitter/XmlPrettyPrinter.java index f97777c..c314e18 100644 --- a/jxmpp-core/src/main/java/org/jxmpp/xml/splitter/XmlPrettyPrinter.java +++ b/jxmpp-core/src/main/java/org/jxmpp/xml/splitter/XmlPrettyPrinter.java @@ -117,6 +117,11 @@ void onNextChar(char c, int depth, State initialState, State currentState) throw case START: indent = getElementIndent(depth); break; + case IN_PROCESSING_INSTRUCTION_OR_DECLARATION: + if (initialState == State.TAG_LEFT_ANGLE_BRACKET) { + deferredLeftAngle = true; + } + break; } if (indent > 0 || deferredLeftAngle) { diff --git a/jxmpp-core/src/test/java/org/jxmpp/xml/splitter/XmlPrettyPrinterTest.java b/jxmpp-core/src/test/java/org/jxmpp/xml/splitter/XmlPrettyPrinterTest.java index f314e73..1bb9e7f 100644 --- a/jxmpp-core/src/test/java/org/jxmpp/xml/splitter/XmlPrettyPrinterTest.java +++ b/jxmpp-core/src/test/java/org/jxmpp/xml/splitter/XmlPrettyPrinterTest.java @@ -77,6 +77,18 @@ public void simplePrettyPrintTestTabIndent() throws IOException { xmlPrettyPrintTest(expectedPrettyPrintedXml, inputXml, xmlPrettyPrinterBuilder); } + @Test + public void simplePrettyPrintTestDeclaration() throws IOException { + String inputXml = "\n

"; + String expectedPrettyPrintedXml = + "\n\n

"; + XmlPrettyPrinter.Builder xmlPrettyPrinterBuilder = XmlPrettyPrinter + .builder() + .setTabWidth(2); + + xmlPrettyPrintTest(expectedPrettyPrintedXml, inputXml, xmlPrettyPrinterBuilder); + } + private static void xmlPrettyPrintTest(String expectedPrettyPrintedXml, String inputXml, XmlPrettyPrinter.Builder xmlPrettyPrinterBuilder) throws IOException { final StringHolder stringHolder = new StringHolder();