Skip to content

Commit 4bc3c02

Browse files
cristopermmcdole
authored andcommitted
Add test for absolute path as xml:base
I wanted to prove to myself that the current xml:base implementation handles absolute paths with no domain part (as in "xml:base=/absolute") by replacing the current base path (as illustrate in the spec example: https://www.w3.org/TR/xmlbase/) All tests pass.
1 parent a0c3115 commit 4bc3c02

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

xpp_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,36 +89,36 @@ func TestXMLBase(t *testing.T) {
8989
crReader := func(charset string, input io.Reader) (io.Reader, error) {
9090
return input, nil
9191
}
92-
r := bytes.NewBufferString(`<root xml:base="https://example.org/"><d2 xml:base="relative">foo</d2><d2>bar</d2><d2>baz</d2></root>`)
92+
r := bytes.NewBufferString(`<root xml:base="https://example.org/path/"><d2 xml:base="relative">foo</d2><d2 xml:base="/absolute">bar</d2><d2>baz</d2></root>`)
9393
p := xpp.NewXMLPullParser(r, false, crReader)
9494

9595
type v struct{}
9696

9797
// move to root
9898
p.NextTag()
9999
assert.Equal(t, "root", p.Name)
100-
assert.Equal(t, "https://example.org/", p.BaseStack.Top().String())
100+
assert.Equal(t, "https://example.org/path/", p.BaseStack.Top().String())
101101

102102
// decode first <d2>
103103
p.NextTag()
104104
assert.Equal(t, "d2", p.Name)
105-
assert.Equal(t, "https://example.org/relative", p.BaseStack.Top().String())
105+
assert.Equal(t, "https://example.org/path/relative", p.BaseStack.Top().String())
106106

107107
resolved, err := p.XmlBaseResolveUrl("test")
108108
assert.NoError(t, err)
109-
assert.Equal(t, "https://example.org/relative/test", resolved.String())
109+
assert.Equal(t, "https://example.org/path/relative/test", resolved.String())
110110
p.DecodeElement(&v{})
111111

112112
// decode second <d2>
113113
p.NextTag()
114114
assert.Equal(t, "d2", p.Name)
115-
assert.Equal(t, "https://example.org/", p.BaseStack.Top().String())
115+
assert.Equal(t, "https://example.org/absolute", p.BaseStack.Top().String())
116116
p.DecodeElement(&v{})
117117

118118
// ensure xml:base is still set to root element's base
119119
p.NextTag()
120120
assert.Equal(t, "d2", p.Name)
121-
assert.Equal(t, "https://example.org/", p.BaseStack.Top().String())
121+
assert.Equal(t, "https://example.org/path/", p.BaseStack.Top().String())
122122
}
123123

124124
func toNextStart(t *testing.T, p *xpp.XMLPullParser) {

0 commit comments

Comments
 (0)