File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -1008,6 +1008,13 @@ public String format(int indent) {
10081008 return singleLine ;
10091009 }
10101010
1011+ // Might just be whitespace, which won't be valid XML. And in that case,
1012+ // even adding the decl to the top seems dumb, so don't spew out a decl.
1013+ // https://github.com/processing/processing/issues/1796
1014+ if (singleLine .trim ().length () == 0 ) {
1015+ return "" ;
1016+ }
1017+
10111018 // Since the indent is not -1, bring back the XML declaration
10121019 //transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
10131020
@@ -1016,8 +1023,13 @@ public String format(int indent) {
10161023// DOMSource source = new DOMSource(node);
10171024 Source source = new StreamSource (new StringReader (singleLine ));
10181025 transformer .transform (source , xmlOutput );
1019- return decl + sep + stringWriter .toString ();
1020- // return xmlOutput.getWriter().toString();
1026+ String outgoing = stringWriter .toString ();
1027+ if (!outgoing .startsWith (decl )) {
1028+ // Add the XML declaration to the top if it's not there already
1029+ return decl + sep + outgoing ;
1030+ } else {
1031+ return outgoing ;
1032+ }
10211033
10221034 } catch (Exception e ) {
10231035 e .printStackTrace ();
You can’t perform that action at this time.
0 commit comments