1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2026-06-17 23:17:46 +02:00
Files

38 lines
800 B
Go
Raw Permalink Normal View History

2025-11-27 01:43:04 +06:00
package xmlparser
import (
"io"
)
type Document struct {
Node
}
func NewDocument(r io.Reader) (*Document, error) {
doc := &Document{
Node: Node{
// Attributes for document are always empty, but they are exposed,
// so we need to initialize them to avoid nil pointer dereference.
Attrs: NewAttributes(),
},
}
if err := doc.readFrom(r); err != nil {
return nil, err
}
return doc, nil
}
// ReplaceEntities replaces XML entities in the document
// according to the entity declarations in the DOCTYPE.
// It modifies the document in place.
//
// Entities are replaced only once to avoid attacks like the
// "Billion Laughs" XML entity expansion attack.
func (doc *Document) ReplaceEntities() {
2026-03-18 19:55:09 +03:00
if em := ParseEntityMap(doc.Children); em != nil {
2025-11-27 01:43:04 +06:00
doc.replaceEntities(em)
}
}