chore(deps): bump github.com/beevik/etree from 1.4.0 to 1.4.1

Bumps [github.com/beevik/etree](https://github.com/beevik/etree) from 1.4.0 to 1.4.1.
- [Release notes](https://github.com/beevik/etree/releases)
- [Changelog](https://github.com/beevik/etree/blob/main/RELEASE_NOTES.md)
- [Commits](https://github.com/beevik/etree/compare/v1.4.0...v1.4.1)

---
updated-dependencies:
- dependency-name: github.com/beevik/etree
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
dependabot[bot]
2024-08-08 06:57:38 +00:00
committed by Ralf Haferkamp
parent 3247fa0a38
commit ed13b043eb
7 changed files with 106 additions and 99 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ require (
github.com/MicahParks/keyfunc v1.9.0 github.com/MicahParks/keyfunc v1.9.0
github.com/Nerzal/gocloak/v13 v13.9.0 github.com/Nerzal/gocloak/v13 v13.9.0
github.com/bbalet/stopwords v1.0.0 github.com/bbalet/stopwords v1.0.0
github.com/beevik/etree v1.4.0 github.com/beevik/etree v1.4.1
github.com/blevesearch/bleve/v2 v2.4.2 github.com/blevesearch/bleve/v2 v2.4.2
github.com/cenkalti/backoff v2.2.1+incompatible github.com/cenkalti/backoff v2.2.1+incompatible
github.com/coreos/go-oidc/v3 v3.11.0 github.com/coreos/go-oidc/v3 v3.11.0
+2 -2
View File
@@ -139,8 +139,8 @@ github.com/aws/aws-sdk-go v1.45.1/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Ph
github.com/bbalet/stopwords v1.0.0 h1:0TnGycCtY0zZi4ltKoOGRFIlZHv0WqpoIGUsObjztfo= github.com/bbalet/stopwords v1.0.0 h1:0TnGycCtY0zZi4ltKoOGRFIlZHv0WqpoIGUsObjztfo=
github.com/bbalet/stopwords v1.0.0/go.mod h1:sAWrQoDMfqARGIn4s6dp7OW7ISrshUD8IP2q3KoqPjc= github.com/bbalet/stopwords v1.0.0/go.mod h1:sAWrQoDMfqARGIn4s6dp7OW7ISrshUD8IP2q3KoqPjc=
github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A= github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A=
github.com/beevik/etree v1.4.0 h1:oz1UedHRepuY3p4N5OjE0nK1WLCqtzHf25bxplKOHLs= github.com/beevik/etree v1.4.1 h1:PmQJDDYahBGNKDcpdX8uPy1xRCwoCGVUiW669MEirVI=
github.com/beevik/etree v1.4.0/go.mod h1:cyWiXwGoasx60gHvtnEh5x8+uIjUVnjWqBvEnhnqKDA= github.com/beevik/etree v1.4.1/go.mod h1:gPNJNaBGVZ9AwsidazFZyygnd+0pAU38N4D+WemwKNs=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o= github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o=
github.com/benbjohnson/clock v1.3.5/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/benbjohnson/clock v1.3.5/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
+9
View File
@@ -1,3 +1,12 @@
Release 1.4.1
=============
**Changes**
* Minimal go version updated to 1.21.
* Default-initialized CharsetReader causes same result as NewDocument().
* When reading an XML document, attributes are parsed more efficiently.
Release v1.4.0 Release v1.4.0
============== ==============
+69 -71
View File
@@ -13,7 +13,7 @@ import (
"errors" "errors"
"io" "io"
"os" "os"
"sort" "slices"
"strings" "strings"
) )
@@ -31,9 +31,14 @@ var ErrXML = errors.New("etree: invalid XML format")
var cdataPrefix = []byte("<![CDATA[") var cdataPrefix = []byte("<![CDATA[")
// ReadSettings determine the default behavior of the Document's ReadFrom* // ReadSettings determine the default behavior of the Document's ReadFrom*
// methods. // functions.
type ReadSettings struct { type ReadSettings struct {
// CharsetReader to be passed to standard xml.Decoder. Default: nil. // CharsetReader, if non-nil, defines a function to generate
// charset-conversion readers, converting from the provided non-UTF-8
// charset into UTF-8. If nil, the ReadFrom* functions will use a
// "pass-through" CharsetReader that performs no conversion on the reader's
// data regardless of the value of the "charset" encoding string. Default:
// nil.
CharsetReader func(charset string, input io.Reader) (io.Reader, error) CharsetReader func(charset string, input io.Reader) (io.Reader, error)
// Permissive allows input containing common mistakes such as missing tags // Permissive allows input containing common mistakes such as missing tags
@@ -50,11 +55,16 @@ type ReadSettings struct {
// preserve them instead of keeping only one. Default: false. // preserve them instead of keeping only one. Default: false.
PreserveDuplicateAttrs bool PreserveDuplicateAttrs bool
// ValidateInput forces all ReadFrom* methods to validate that the // ValidateInput forces all ReadFrom* functions to validate that the
// provided input is composed of well-formed XML before processing it. If // provided input is composed of "well-formed"(*) XML before processing it.
// invalid XML is detected, the ReadFrom* methods return an error. Because // If invalid XML is detected, the ReadFrom* functions return an error.
// this option requires the input to be processed twice, it incurs a // Because this option requires the input to be processed twice, it incurs a
// significant performance penalty. Default: false. // significant performance penalty. Default: false.
//
// (*) Note that this definition of "well-formed" is in the context of the
// go standard library's encoding/xml package. Go's encoding/xml package
// does not, in fact, guarantee well-formed XML as specified by the W3C XML
// recommendation. See: https://github.com/golang/go/issues/68299
ValidateInput bool ValidateInput bool
// Entity to be passed to standard xml.Decoder. Default: nil. // Entity to be passed to standard xml.Decoder. Default: nil.
@@ -67,13 +77,11 @@ type ReadSettings struct {
AutoClose []string AutoClose []string
} }
// newReadSettings creates a default ReadSettings record. // defaultCharsetReader is used by the xml decoder when the ReadSettings
func newReadSettings() ReadSettings { // CharsetReader value is nil. It behaves as a "pass-through", ignoring
return ReadSettings{ // the requested charset parameter and skipping conversion altogether.
CharsetReader: func(label string, input io.Reader) (io.Reader, error) { func defaultCharsetReader(charset string, input io.Reader) (io.Reader, error) {
return input, nil return input, nil
},
}
} }
// dup creates a duplicate of the ReadSettings object. // dup creates a duplicate of the ReadSettings object.
@@ -92,7 +100,7 @@ func (s *ReadSettings) dup() ReadSettings {
} }
} }
// WriteSettings determine the behavior of the Document's WriteTo* methods. // WriteSettings determine the behavior of the Document's WriteTo* functions.
type WriteSettings struct { type WriteSettings struct {
// CanonicalEndTags forces the production of XML end tags, even for // CanonicalEndTags forces the production of XML end tags, even for
// elements that have no child elements. Default: false. // elements that have no child elements. Default: false.
@@ -113,7 +121,7 @@ type WriteSettings struct {
// false. // false.
AttrSingleQuote bool AttrSingleQuote bool
// UseCRLF causes the document's Indent* methods to use a carriage return // UseCRLF causes the document's Indent* functions to use a carriage return
// followed by a linefeed ("\r\n") when outputting a newline. If false, // followed by a linefeed ("\r\n") when outputting a newline. If false,
// only a linefeed is used ("\n"). Default: false. // only a linefeed is used ("\n"). Default: false.
// //
@@ -121,23 +129,12 @@ type WriteSettings struct {
UseCRLF bool UseCRLF bool
} }
// newWriteSettings creates a default WriteSettings record.
func newWriteSettings() WriteSettings {
return WriteSettings{
CanonicalEndTags: false,
CanonicalText: false,
CanonicalAttrVal: false,
AttrSingleQuote: false,
UseCRLF: false,
}
}
// dup creates a duplicate of the WriteSettings object. // dup creates a duplicate of the WriteSettings object.
func (s *WriteSettings) dup() WriteSettings { func (s *WriteSettings) dup() WriteSettings {
return *s return *s
} }
// IndentSettings determine the behavior of the Document's Indent* methods. // IndentSettings determine the behavior of the Document's Indent* functions.
type IndentSettings struct { type IndentSettings struct {
// Spaces indicates the number of spaces to insert for each level of // Spaces indicates the number of spaces to insert for each level of
// indentation. Set to etree.NoIndent to remove all indentation. Ignored // indentation. Set to etree.NoIndent to remove all indentation. Ignored
@@ -153,7 +150,7 @@ type IndentSettings struct {
// for a newline ("\n"). Default: false. // for a newline ("\n"). Default: false.
UseCRLF bool UseCRLF bool
// PreserveLeafWhitespace causes indent methods to preserve whitespace // PreserveLeafWhitespace causes indent functions to preserve whitespace
// within XML elements containing only non-CDATA character data. Default: // within XML elements containing only non-CDATA character data. Default:
// false. // false.
PreserveLeafWhitespace bool PreserveLeafWhitespace bool
@@ -195,7 +192,7 @@ func getIndentFunc(s *IndentSettings) indentFunc {
} }
} }
// Writer is the interface that wraps the Write* methods called by each token // Writer is the interface that wraps the Write* functions called by each token
// type's WriteTo function. // type's WriteTo function.
type Writer interface { type Writer interface {
io.StringWriter io.StringWriter
@@ -260,7 +257,7 @@ const (
// CharData may be used to represent simple text data or a CDATA section // CharData may be used to represent simple text data or a CDATA section
// within an XML document. The Data property should never be modified // within an XML document. The Data property should never be modified
// directly; use the SetData method instead. // directly; use the SetData function instead.
type CharData struct { type CharData struct {
Data string // the simple text or CDATA section content Data string // the simple text or CDATA section content
parent *Element parent *Element
@@ -293,9 +290,7 @@ type ProcInst struct {
// NewDocument creates an XML document without a root element. // NewDocument creates an XML document without a root element.
func NewDocument() *Document { func NewDocument() *Document {
return &Document{ return &Document{
Element: Element{Child: make([]Token, 0)}, Element: Element{Child: make([]Token, 0)},
ReadSettings: newReadSettings(),
WriteSettings: newWriteSettings(),
} }
} }
@@ -428,6 +423,9 @@ func validateXML(r io.Reader, settings ReadSettings) error {
func newDecoder(r io.Reader, settings ReadSettings) *xml.Decoder { func newDecoder(r io.Reader, settings ReadSettings) *xml.Decoder {
d := xml.NewDecoder(r) d := xml.NewDecoder(r)
d.CharsetReader = settings.CharsetReader d.CharsetReader = settings.CharsetReader
if d.CharsetReader == nil {
d.CharsetReader = defaultCharsetReader
}
d.Strict = !settings.Permissive d.Strict = !settings.Permissive
d.Entity = settings.Entity d.Entity = settings.Entity
d.AutoClose = settings.AutoClose d.AutoClose = settings.AutoClose
@@ -858,12 +856,12 @@ func (e *Element) RemoveChildAt(index int) Token {
// autoClose analyzes the stack's top element and the current token to decide // autoClose analyzes the stack's top element and the current token to decide
// whether the top element should be closed. // whether the top element should be closed.
func (e *Element) autoClose(stack *stack, t xml.Token, tags []string) { func (e *Element) autoClose(stack *stack[*Element], t xml.Token, tags []string) {
if stack.empty() { if stack.empty() {
return return
} }
top := stack.peek().(*Element) top := stack.peek()
for _, tag := range tags { for _, tag := range tags {
if strings.EqualFold(tag, top.FullTag()) { if strings.EqualFold(tag, top.FullTag()) {
@@ -889,9 +887,10 @@ func (e *Element) readFrom(ri io.Reader, settings ReadSettings) (n int64, err er
r = newXmlSimpleReader(ri) r = newXmlSimpleReader(ri)
} }
attrCheck := make(map[xml.Name]int)
dec := newDecoder(r, settings) dec := newDecoder(r, settings)
var stack stack var stack stack[*Element]
stack.push(e) stack.push(e)
for { for {
if pr != nil { if pr != nil {
@@ -916,13 +915,24 @@ func (e *Element) readFrom(ri io.Reader, settings ReadSettings) (n int64, err er
return r.Bytes(), ErrXML return r.Bytes(), ErrXML
} }
top := stack.peek().(*Element) top := stack.peek()
switch t := t.(type) { switch t := t.(type) {
case xml.StartElement: case xml.StartElement:
e := newElement(t.Name.Space, t.Name.Local, top) e := newElement(t.Name.Space, t.Name.Local, top)
for _, a := range t.Attr { if settings.PreserveDuplicateAttrs || len(t.Attr) < 2 {
e.createAttr(a.Name.Space, a.Name.Local, a.Value, e, settings.PreserveDuplicateAttrs) for _, a := range t.Attr {
e.addAttr(a.Name.Space, a.Name.Local, a.Value)
}
} else {
for _, a := range t.Attr {
if i, contains := attrCheck[a.Name]; contains {
e.Attr[i].Value = a.Value
} else {
attrCheck[a.Name] = e.addAttr(a.Name.Space, a.Name.Local, a.Value)
}
}
clear(attrCheck)
} }
stack.push(e) stack.push(e)
case xml.EndElement: case xml.EndElement:
@@ -1365,28 +1375,29 @@ func (e *Element) addChild(t Token) {
// prefix followed by a colon. // prefix followed by a colon.
func (e *Element) CreateAttr(key, value string) *Attr { func (e *Element) CreateAttr(key, value string) *Attr {
space, skey := spaceDecompose(key) space, skey := spaceDecompose(key)
return e.createAttr(space, skey, value, e, false)
}
// createAttr is a helper function that creates attributes. for i, a := range e.Attr {
func (e *Element) createAttr(space, key, value string, parent *Element, preserveDups bool) *Attr { if space == a.Space && skey == a.Key {
if !preserveDups { e.Attr[i].Value = value
for i, a := range e.Attr { return &e.Attr[i]
if space == a.Space && key == a.Key {
e.Attr[i].Value = value
return &e.Attr[i]
}
} }
} }
i := e.addAttr(space, skey, value)
return &e.Attr[i]
}
// addAttr is a helper function that adds an attribute to an element. Returns
// the index of the added attribute.
func (e *Element) addAttr(space, key, value string) int {
a := Attr{ a := Attr{
Space: space, Space: space,
Key: key, Key: key,
Value: value, Value: value,
element: parent, element: e,
} }
e.Attr = append(e.Attr, a) e.Attr = append(e.Attr, a)
return &e.Attr[len(e.Attr)-1] return len(e.Attr) - 1
} }
// RemoveAttr removes the first attribute of this element whose key matches // RemoveAttr removes the first attribute of this element whose key matches
@@ -1411,25 +1422,12 @@ func (e *Element) RemoveAttr(key string) *Attr {
// SortAttrs sorts this element's attributes lexicographically by key. // SortAttrs sorts this element's attributes lexicographically by key.
func (e *Element) SortAttrs() { func (e *Element) SortAttrs() {
sort.Sort(byAttr(e.Attr)) slices.SortFunc(e.Attr, func(a, b Attr) int {
} if v := strings.Compare(a.Space, b.Space); v != 0 {
return v
type byAttr []Attr }
return strings.Compare(a.Key, b.Key)
func (a byAttr) Len() int { })
return len(a)
}
func (a byAttr) Swap(i, j int) {
a[i], a[j] = a[j], a[i]
}
func (a byAttr) Less(i, j int) bool {
sp := strings.Compare(a[i].Space, a[j].Space)
if sp == 0 {
return strings.Compare(a[i].Key, a[j].Key) < 0
}
return sp < 0
} }
// FullKey returns this attribute's complete key, including namespace prefix // FullKey returns this attribute's complete key, including namespace prefix
+19 -19
View File
@@ -10,37 +10,36 @@ import (
"unicode/utf8" "unicode/utf8"
) )
// A simple stack type stack[E any] struct {
type stack struct { data []E
data []interface{}
} }
func (s *stack) empty() bool { func (s *stack[E]) empty() bool {
return len(s.data) == 0 return len(s.data) == 0
} }
func (s *stack) push(value interface{}) { func (s *stack[E]) push(value E) {
s.data = append(s.data, value) s.data = append(s.data, value)
} }
func (s *stack) pop() interface{} { func (s *stack[E]) pop() E {
value := s.data[len(s.data)-1] value := s.data[len(s.data)-1]
s.data[len(s.data)-1] = nil var empty E
s.data[len(s.data)-1] = empty
s.data = s.data[:len(s.data)-1] s.data = s.data[:len(s.data)-1]
return value return value
} }
func (s *stack) peek() interface{} { func (s *stack[E]) peek() E {
return s.data[len(s.data)-1] return s.data[len(s.data)-1]
} }
// A fifo is a simple first-in-first-out queue. type queue[E any] struct {
type fifo struct { data []E
data []interface{}
head, tail int head, tail int
} }
func (f *fifo) add(value interface{}) { func (f *queue[E]) add(value E) {
if f.len()+1 >= len(f.data) { if f.len()+1 >= len(f.data) {
f.grow() f.grow()
} }
@@ -50,33 +49,34 @@ func (f *fifo) add(value interface{}) {
} }
} }
func (f *fifo) remove() interface{} { func (f *queue[E]) remove() E {
value := f.data[f.head] value := f.data[f.head]
f.data[f.head] = nil var empty E
f.data[f.head] = empty
if f.head++; f.head == len(f.data) { if f.head++; f.head == len(f.data) {
f.head = 0 f.head = 0
} }
return value return value
} }
func (f *fifo) len() int { func (f *queue[E]) len() int {
if f.tail >= f.head { if f.tail >= f.head {
return f.tail - f.head return f.tail - f.head
} }
return len(f.data) - f.head + f.tail return len(f.data) - f.head + f.tail
} }
func (f *fifo) grow() { func (f *queue[E]) grow() {
c := len(f.data) * 2 c := len(f.data) * 2
if c == 0 { if c == 0 {
c = 4 c = 4
} }
buf, count := make([]interface{}, c), f.len() buf, count := make([]E, c), f.len()
if f.tail >= f.head { if f.tail >= f.head {
copy(buf[0:count], f.data[f.head:f.tail]) copy(buf[:count], f.data[f.head:f.tail])
} else { } else {
hindex := len(f.data) - f.head hindex := len(f.data) - f.head
copy(buf[0:hindex], f.data[f.head:]) copy(buf[:hindex], f.data[f.head:])
copy(buf[hindex:count], f.data[:f.tail]) copy(buf[hindex:count], f.data[:f.tail])
} }
f.data, f.head, f.tail = buf, 0, count f.data, f.head, f.tail = buf, 0, count
+4 -4
View File
@@ -152,7 +152,7 @@ type filter interface {
// a Path object. It collects and deduplicates all elements matching // a Path object. It collects and deduplicates all elements matching
// the path query. // the path query.
type pather struct { type pather struct {
queue fifo queue queue[node]
results []*Element results []*Element
inResults map[*Element]bool inResults map[*Element]bool
candidates []*Element candidates []*Element
@@ -180,7 +180,7 @@ func newPather() *pather {
// and filters. // and filters.
func (p *pather) traverse(e *Element, path Path) []*Element { func (p *pather) traverse(e *Element, path Path) []*Element {
for p.queue.add(node{e, path.segments}); p.queue.len() > 0; { for p.queue.add(node{e, path.segments}); p.queue.len() > 0; {
p.eval(p.queue.remove().(node)) p.eval(p.queue.remove())
} }
return p.results return p.results
} }
@@ -406,9 +406,9 @@ func (s *selectChildren) apply(e *Element, p *pather) {
type selectDescendants struct{} type selectDescendants struct{}
func (s *selectDescendants) apply(e *Element, p *pather) { func (s *selectDescendants) apply(e *Element, p *pather) {
var queue fifo var queue queue[*Element]
for queue.add(e); queue.len() > 0; { for queue.add(e); queue.len() > 0; {
e := queue.remove().(*Element) e := queue.remove()
p.candidates = append(p.candidates, e) p.candidates = append(p.candidates, e)
for _, c := range e.Child { for _, c := range e.Child {
if c, ok := c.(*Element); ok { if c, ok := c.(*Element); ok {
+2 -2
View File
@@ -148,8 +148,8 @@ github.com/aws/aws-sdk-go/service/sts/stsiface
# github.com/bbalet/stopwords v1.0.0 # github.com/bbalet/stopwords v1.0.0
## explicit ## explicit
github.com/bbalet/stopwords github.com/bbalet/stopwords
# github.com/beevik/etree v1.4.0 # github.com/beevik/etree v1.4.1
## explicit; go 1.16 ## explicit; go 1.21.0
github.com/beevik/etree github.com/beevik/etree
# github.com/beorn7/perks v1.0.1 # github.com/beorn7/perks v1.0.1
## explicit; go 1.11 ## explicit; go 1.11