Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b113c04

Browse files
committedSep 27, 2021
encoding/xml: gofmt
1 parent aba6f79 commit b113c04

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed
 

‎src/encoding/xml/marshal.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,12 @@ func (p *printer) popPrefix() {
400400
p.deleteAttrPrefix(prefix)
401401
}
402402
}
403+
403404
// No prefix is returned if the first prefix of the list for this tag is not assigned to a namespace
404405
func (p *printer) tagPrefix() string {
405406
prefix := p.prefixes[len(p.prefixes)-1] // last prefix relates to current tag
406407
i := len(p.prefixes) - 1
407-
for i >= 0 && i < len(p.prefixes){
408+
for i >= 0 && i < len(p.prefixes) {
408409
if prefix == "" { // end of list of prefixes for this tag is reached
409410
// check that previous prefix is the one of the tag
410411
if i+1 < len(p.prefixes) { // list is not empty
@@ -763,7 +764,7 @@ func (p *printer) writeStart(start *StartElement) error {
763764
}
764765
}
765766
if prefixToPrint == "" { // no prefix was found for the space of the tag name
766-
// the tag name Space is then considered as the default xmlns=".Space"
767+
// the tag name Space is then considered as the default xmlns=".Space"
767768
for _, attr := range start.Attr {
768769
// attributes values which are namespaces are searched to avoid reprinting the default
769770
if start.Name.Space == attr.Value && attr.Name.Space == "" && attr.Name.Local == xmlnsPrefix {
@@ -779,7 +780,7 @@ func (p *printer) writeStart(start *StartElement) error {
779780
p.WriteString(start.Name.Local) // tag name
780781
} else {
781782
p.WriteString(start.Name.Local) // no prefix found
782-
p.WriteString(` xmlns="`) // printing the namespace taken as default without prefix
783+
p.WriteString(` xmlns="`) // printing the namespace taken as default without prefix
783784
p.EscapeString(start.Name.Space)
784785
p.WriteByte('"')
785786
}
@@ -798,7 +799,7 @@ func (p *printer) writeStart(start *StartElement) error {
798799
p.WriteByte(':')
799800
} else if attr.Name.Space != "" { // not a name space {.Space}:{.Local}={.Value} and .Local is not xmlns
800801
p.WriteString(p.createAttrPrefix(attr.Name.Space)) // name.Space is not a prefix but nothing should be done
801-
p.WriteByte(':') // about it if another one exists
802+
p.WriteByte(':') // about it if another one exists
802803
}
803804
// When space is empty, only writing .Local=.Value which will also be xmlns=".Value"
804805
p.WriteString(attr.Name.Local)

‎src/encoding/xml/marshal_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -2082,7 +2082,7 @@ var encodeTokenTests = []struct {
20822082
{Name{"xmlns", "x"}, "space"},
20832083
{Name{"space", "foo"}, "value"},
20842084
}},
2085-
},// #16 <x:local xmlns:x="space" space:foo="value">
2085+
}, // #16 <x:local xmlns:x="space" space:foo="value">
20862086
want: `<x:local xmlns:x="space" xmlns:space="space" space:foo="value">`,
20872087
}, {
20882088
desc: "start element with explicit namespace and colliding prefix",
@@ -2136,7 +2136,7 @@ var encodeTokenTests = []struct {
21362136
{Name{"xmlns", "b"}, "space"}, // xmlns:b="space"
21372137
{Name{"space", "x"}, "value"}, // space:x="value"
21382138
}},
2139-
},// #20
2139+
}, // #20
21402140
want: `<a:foo xmlns:a="space" xmlns:b="space" xmlns:space="space" space:x="value">`,
21412141
}, {
21422142
desc: "nested element redefines name space",
@@ -2172,7 +2172,7 @@ var encodeTokenTests = []struct {
21722172
{Name{"", "xmlns"}, "space"}, // xlmns="space"
21732173
{Name{"space", "a"}, "value"}, // space:a="value"
21742174
}},
2175-
},// #23 Keeps its oddity
2175+
}, // #23 Keeps its oddity
21762176
want: `<foo xmlns:x="space"><foo xmlns="space" xmlns:space="space" space:a="value">`,
21772177
}, {
21782178
desc: "nested element uses empty attribute name space when default ns defined",
@@ -2183,7 +2183,7 @@ var encodeTokenTests = []struct {
21832183
StartElement{Name{"space", "foo"}, []Attr{
21842184
{Name{"", "attr"}, "value"},
21852185
}},
2186-
},// #24 Purpose is to produce valid xml
2186+
}, // #24 Purpose is to produce valid xml
21872187
want: `<foo xmlns="space"><foo xmlns="space" attr="value">`,
21882188
}, {
21892189
desc: "redefine xmlns",
@@ -2240,8 +2240,8 @@ var encodeTokenTests = []struct {
22402240
{Name{"", "xmlns"}, "space"},
22412241
}},
22422242
StartElement{Name{"", "foo"}, []Attr{
2243-
{Name{"", "xmlns"}, ""}, // xmlns=""
2244-
{Name{"", "x"}, "value"}, // x="value"
2243+
{Name{"", "xmlns"}, ""}, // xmlns=""
2244+
{Name{"", "x"}, "value"}, // x="value"
22452245
{Name{"space", "x"}, "value"}, // space:x="value"
22462246
}},
22472247
}, // #31 xmlns:space="space" oddity still appears
@@ -2281,8 +2281,8 @@ var encodeTokenTests = []struct {
22812281
desc: "default name space not used by attributes, not explicitly defined",
22822282
toks: []Token{
22832283
StartElement{Name{"space", "foo"}, []Attr{
2284-
{Name{"", "xmlns"}, "space"}, // xmlns="space"
2285-
{Name{"space", "baz"}, "foo"}, // space:baz="foo"
2284+
{Name{"", "xmlns"}, "space"}, // xmlns="space"
2285+
{Name{"space", "baz"}, "foo"}, // space:baz="foo"
22862286
}},
22872287
StartElement{Name{"space", "baz"}, nil},
22882288
EndElement{Name{"space", "baz"}},

0 commit comments

Comments
 (0)
Please sign in to comment.