diff --git a/internal/utils/utils.go b/internal/utils/utils.go
index 2597b2a..ea7b479 100644
--- a/internal/utils/utils.go
+++ b/internal/utils/utils.go
@@ -94,10 +94,16 @@ func FormatXml(reader io.Reader, writer io.Writer, indent string, colors int) er
_, _ = fmt.Fprintf(writer, "%s%s", tagColor(""), typedToken.Target)
pi := strings.TrimSpace(string(typedToken.Inst))
- attrs := strings.Split(pi, " ")
- for _, attr := range attrs {
- attrComponents := strings.SplitN(attr, "=", 2)
- _, _ = fmt.Fprintf(writer, " %s%s", attrComponents[0], attrColor("="+attrComponents[1]))
+ if pi != "" {
+ attrs := strings.Split(pi, " ")
+ for _, attr := range attrs {
+ attrComponents := strings.SplitN(attr, "=", 2)
+ if len(attrComponents) == 2 {
+ _, _ = fmt.Fprintf(writer, " %s%s", attrComponents[0], attrColor("="+attrComponents[1]))
+ } else {
+ _, _ = fmt.Fprintf(writer, " %s", attrComponents[0])
+ }
+ }
}
_, _ = fmt.Fprint(writer, tagColor("?>"), newline)
diff --git a/internal/utils/utils_test.go b/internal/utils/utils_test.go
index b0ffd78..b3116ea 100644
--- a/internal/utils/utils_test.go
+++ b/internal/utils/utils_test.go
@@ -39,6 +39,7 @@ func TestFormatXml(t *testing.T) {
"unformatted14.xml": "formatted14.xml",
"unformatted15.xml": "formatted15.xml",
"unformatted16.xml": "formatted16.xml",
+ "unformatted17.xml": "formatted17.xml",
}
for unformattedFile, expectedFile := range files {
diff --git a/test/data/xml/formatted17.xml b/test/data/xml/formatted17.xml
new file mode 100644
index 0000000..56af9ae
--- /dev/null
+++ b/test/data/xml/formatted17.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+ Test
+
+
diff --git a/test/data/xml/unformatted17.xml b/test/data/xml/unformatted17.xml
new file mode 100644
index 0000000..37933bc
--- /dev/null
+++ b/test/data/xml/unformatted17.xml
@@ -0,0 +1,4 @@
+
+
+
+Test