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

2
go.mod
View File

@@ -10,7 +10,7 @@ require (
github.com/MicahParks/keyfunc v1.9.0
github.com/Nerzal/gocloak/v13 v13.9.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/cenkalti/backoff v2.2.1+incompatible
github.com/coreos/go-oidc/v3 v3.11.0

4
go.sum
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/go.mod h1:sAWrQoDMfqARGIn4s6dp7OW7ISrshUD8IP2q3KoqPjc=
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.0/go.mod h1:cyWiXwGoasx60gHvtnEh5x8+uIjUVnjWqBvEnhnqKDA=
github.com/beevik/etree v1.4.1 h1:PmQJDDYahBGNKDcpdX8uPy1xRCwoCGVUiW669MEirVI=
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.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o=
github.com/benbjohnson/clock v1.3.5/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=

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
==============

View File

@@ -13,7 +13,7 @@ import (
"errors"
"io"
"os"
"sort"
"slices"
"strings"
)
@@ -31,9 +31,14 @@ var ErrXML = errors.New("etree: invalid XML format")
var cdataPrefix = []byte("<![CDATA[")
// ReadSettings determine the default behavior of the Document's ReadFrom*
// methods.
// functions.
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)
// 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.
PreserveDuplicateAttrs bool
// ValidateInput forces all ReadFrom* methods to validate that the
// provided input is composed of well-formed XML before processing it. If
// invalid XML is detected, the ReadFrom* methods return an error. Because
// this option requires the input to be processed twice, it incurs a
// ValidateInput forces all ReadFrom* functions to validate that the
// provided input is composed of "well-formed"(*) XML before processing it.
// If invalid XML is detected, the ReadFrom* functions return an error.
// Because this option requires the input to be processed twice, it incurs a
// 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
// Entity to be passed to standard xml.Decoder. Default: nil.
@@ -67,13 +77,11 @@ type ReadSettings struct {
AutoClose []string
}
// newReadSettings creates a default ReadSettings record.
func newReadSettings() ReadSettings {
return ReadSettings{
CharsetReader: func(label string, input io.Reader) (io.Reader, error) {
return input, nil
},
}
// defaultCharsetReader is used by the xml decoder when the ReadSettings
// CharsetReader value is nil. It behaves as a "pass-through", ignoring
// the requested charset parameter and skipping conversion altogether.
func defaultCharsetReader(charset string, input io.Reader) (io.Reader, error) {
return input, nil
}
// 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 {
// CanonicalEndTags forces the production of XML end tags, even for
// elements that have no child elements. Default: false.
@@ -113,7 +121,7 @@ type WriteSettings struct {
// false.
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,
// only a linefeed is used ("\n"). Default: false.
//
@@ -121,23 +129,12 @@ type WriteSettings struct {
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.
func (s *WriteSettings) dup() WriteSettings {
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 {
// Spaces indicates the number of spaces to insert for each level of
// indentation. Set to etree.NoIndent to remove all indentation. Ignored
@@ -153,7 +150,7 @@ type IndentSettings struct {
// for a newline ("\n"). Default: false.
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:
// false.
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 Writer interface {
io.StringWriter
@@ -260,7 +257,7 @@ const (
// CharData may be used to represent simple text data or a CDATA section
// 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 {
Data string // the simple text or CDATA section content
parent *Element
@@ -293,9 +290,7 @@ type ProcInst struct {
// NewDocument creates an XML document without a root element.
func NewDocument() *Document {
return &Document{
Element: Element{Child: make([]Token, 0)},
ReadSettings: newReadSettings(),
WriteSettings: newWriteSettings(),
Element: Element{Child: make([]Token, 0)},
}
}
@@ -428,6 +423,9 @@ func validateXML(r io.Reader, settings ReadSettings) error {
func newDecoder(r io.Reader, settings ReadSettings) *xml.Decoder {
d := xml.NewDecoder(r)
d.CharsetReader = settings.CharsetReader
if d.CharsetReader == nil {
d.CharsetReader = defaultCharsetReader
}
d.Strict = !settings.Permissive
d.Entity = settings.Entity
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
// 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() {
return
}
top := stack.peek().(*Element)
top := stack.peek()
for _, tag := range tags {
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)
}
attrCheck := make(map[xml.Name]int)
dec := newDecoder(r, settings)
var stack stack
var stack stack[*Element]
stack.push(e)
for {
if pr != nil {
@@ -916,13 +915,24 @@ func (e *Element) readFrom(ri io.Reader, settings ReadSettings) (n int64, err er
return r.Bytes(), ErrXML
}
top := stack.peek().(*Element)
top := stack.peek()
switch t := t.(type) {
case xml.StartElement:
e := newElement(t.Name.Space, t.Name.Local, top)
for _, a := range t.Attr {
e.createAttr(a.Name.Space, a.Name.Local, a.Value, e, settings.PreserveDuplicateAttrs)
if settings.PreserveDuplicateAttrs || len(t.Attr) < 2 {
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)
case xml.EndElement:
@@ -1365,28 +1375,29 @@ func (e *Element) addChild(t Token) {
// prefix followed by a colon.
func (e *Element) CreateAttr(key, value string) *Attr {
space, skey := spaceDecompose(key)
return e.createAttr(space, skey, value, e, false)
}
// createAttr is a helper function that creates attributes.
func (e *Element) createAttr(space, key, value string, parent *Element, preserveDups bool) *Attr {
if !preserveDups {
for i, a := range e.Attr {
if space == a.Space && key == a.Key {
e.Attr[i].Value = value
return &e.Attr[i]
}
for i, a := range e.Attr {
if space == a.Space && skey == 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{
Space: space,
Key: key,
Value: value,
element: parent,
element: e,
}
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
@@ -1411,25 +1422,12 @@ func (e *Element) RemoveAttr(key string) *Attr {
// SortAttrs sorts this element's attributes lexicographically by key.
func (e *Element) SortAttrs() {
sort.Sort(byAttr(e.Attr))
}
type byAttr []Attr
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
slices.SortFunc(e.Attr, func(a, b Attr) int {
if v := strings.Compare(a.Space, b.Space); v != 0 {
return v
}
return strings.Compare(a.Key, b.Key)
})
}
// FullKey returns this attribute's complete key, including namespace prefix

View File

@@ -10,37 +10,36 @@ import (
"unicode/utf8"
)
// A simple stack
type stack struct {
data []interface{}
type stack[E any] struct {
data []E
}
func (s *stack) empty() bool {
func (s *stack[E]) empty() bool {
return len(s.data) == 0
}
func (s *stack) push(value interface{}) {
func (s *stack[E]) push(value E) {
s.data = append(s.data, value)
}
func (s *stack) pop() interface{} {
func (s *stack[E]) pop() E {
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]
return value
}
func (s *stack) peek() interface{} {
func (s *stack[E]) peek() E {
return s.data[len(s.data)-1]
}
// A fifo is a simple first-in-first-out queue.
type fifo struct {
data []interface{}
type queue[E any] struct {
data []E
head, tail int
}
func (f *fifo) add(value interface{}) {
func (f *queue[E]) add(value E) {
if f.len()+1 >= len(f.data) {
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]
f.data[f.head] = nil
var empty E
f.data[f.head] = empty
if f.head++; f.head == len(f.data) {
f.head = 0
}
return value
}
func (f *fifo) len() int {
func (f *queue[E]) len() int {
if f.tail >= f.head {
return f.tail - f.head
}
return len(f.data) - f.head + f.tail
}
func (f *fifo) grow() {
func (f *queue[E]) grow() {
c := len(f.data) * 2
if c == 0 {
c = 4
}
buf, count := make([]interface{}, c), f.len()
buf, count := make([]E, c), f.len()
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 {
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])
}
f.data, f.head, f.tail = buf, 0, count

View File

@@ -152,7 +152,7 @@ type filter interface {
// a Path object. It collects and deduplicates all elements matching
// the path query.
type pather struct {
queue fifo
queue queue[node]
results []*Element
inResults map[*Element]bool
candidates []*Element
@@ -180,7 +180,7 @@ func newPather() *pather {
// and filters.
func (p *pather) traverse(e *Element, path Path) []*Element {
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
}
@@ -406,9 +406,9 @@ func (s *selectChildren) apply(e *Element, p *pather) {
type selectDescendants struct{}
func (s *selectDescendants) apply(e *Element, p *pather) {
var queue fifo
var queue queue[*Element]
for queue.add(e); queue.len() > 0; {
e := queue.remove().(*Element)
e := queue.remove()
p.candidates = append(p.candidates, e)
for _, c := range e.Child {
if c, ok := c.(*Element); ok {

4
vendor/modules.txt vendored
View File

@@ -148,8 +148,8 @@ github.com/aws/aws-sdk-go/service/sts/stsiface
# github.com/bbalet/stopwords v1.0.0
## explicit
github.com/bbalet/stopwords
# github.com/beevik/etree v1.4.0
## explicit; go 1.16
# github.com/beevik/etree v1.4.1
## explicit; go 1.21.0
github.com/beevik/etree
# github.com/beorn7/perks v1.0.1
## explicit; go 1.11