From 17a78acd8d8c7698632788c156ce0939c8d113ea Mon Sep 17 00:00:00 2001 From: Marcus Johansson Date: Thu, 31 Oct 2024 14:18:52 +0100 Subject: [PATCH] Support single quotes in attribute for the declaration node Modified the `AddAttr` function to trim both double and single quotes from attribute values. Added a test to ensure XML attributes with single quotes are correctly parsed. --- node_test.go | 10 ++++++++++ parse.go | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/node_test.go b/node_test.go index 21a2d31..0c571ef 100644 --- a/node_test.go +++ b/node_test.go @@ -658,3 +658,13 @@ func TestDirectiveNode(t *testing.T) { t.Errorf(`expected "%s", obtained "%s"`, expected, v) } } + +func TestOutputXMLWithSingleQuotes(t *testing.T) { + s := `` + expected := `` + doc, _ := Parse(strings.NewReader(s)) + output := doc.OutputXML(false) + if expected != output { + t.Errorf(`expected "%s", obtained "%s"`, expected, output) + } +} diff --git a/parse.go b/parse.go index daf7233..7627f46 100644 --- a/parse.go +++ b/parse.go @@ -266,7 +266,7 @@ func (p *parser) parse() (*Node, error) { for _, pair := range pairs { pair = strings.TrimSpace(pair) if i := strings.Index(pair, "="); i > 0 { - AddAttr(node, pair[:i], strings.Trim(pair[i+1:], `"`)) + AddAttr(node, pair[:i], strings.Trim(pair[i+1:], `"'`)) } } if p.level == p.prev.level {