diff options
Diffstat (limited to 'vendor/github.com/tdewolff/parse')
-rw-r--r-- | vendor/github.com/tdewolff/parse/v2/buffer/writer.go | 28 | ||||
-rw-r--r-- | vendor/github.com/tdewolff/parse/v2/strconv/int.go | 20 | ||||
-rw-r--r-- | vendor/github.com/tdewolff/parse/v2/util.go | 21 |
3 files changed, 55 insertions, 14 deletions
diff --git a/vendor/github.com/tdewolff/parse/v2/buffer/writer.go b/vendor/github.com/tdewolff/parse/v2/buffer/writer.go index b3c9990d9..6c94201ff 100644 --- a/vendor/github.com/tdewolff/parse/v2/buffer/writer.go +++ b/vendor/github.com/tdewolff/parse/v2/buffer/writer.go @@ -1,14 +1,29 @@ package buffer +import ( + "io" +) + // Writer implements an io.Writer over a byte slice. type Writer struct { - buf []byte + buf []byte + err error + expand bool } // NewWriter returns a new Writer for a given byte slice. func NewWriter(buf []byte) *Writer { return &Writer{ - buf: buf, + buf: buf, + expand: true, + } +} + +// NewStaticWriter returns a new Writer for a given byte slice. It does not reallocate and expand the byte-slice. +func NewStaticWriter(buf []byte) *Writer { + return &Writer{ + buf: buf, + expand: false, } } @@ -17,6 +32,10 @@ func (w *Writer) Write(b []byte) (int, error) { n := len(b) end := len(w.buf) if end+n > cap(w.buf) { + if !w.expand { + w.err = io.EOF + return 0, io.EOF + } buf := make([]byte, end, 2*cap(w.buf)+n) copy(buf, w.buf) w.buf = buf @@ -39,3 +58,8 @@ func (w *Writer) Bytes() []byte { func (w *Writer) Reset() { w.buf = w.buf[:0] } + +// Close returns the last error. +func (w *Writer) Close() error { + return w.err +} diff --git a/vendor/github.com/tdewolff/parse/v2/strconv/int.go b/vendor/github.com/tdewolff/parse/v2/strconv/int.go index d8df0fd68..e3483bd3a 100644 --- a/vendor/github.com/tdewolff/parse/v2/strconv/int.go +++ b/vendor/github.com/tdewolff/parse/v2/strconv/int.go @@ -38,6 +38,26 @@ func ParseInt(b []byte) (int64, int) { return int64(n), i } +// ParseUint parses a byte-slice and returns the integer it represents. +// If an invalid character is encountered, it will stop there. +func ParseUint(b []byte) (uint64, int) { + i := 0 + n := uint64(0) + for i < len(b) { + c := b[i] + if n > math.MaxUint64/10 { + return 0, 0 + } else if c >= '0' && c <= '9' { + n *= 10 + n += uint64(c - '0') + } else { + break + } + i++ + } + return n, i +} + // LenInt returns the written length of an integer. func LenInt(i int64) int { if i < 0 { diff --git a/vendor/github.com/tdewolff/parse/v2/util.go b/vendor/github.com/tdewolff/parse/v2/util.go index 07101f467..4174cb242 100644 --- a/vendor/github.com/tdewolff/parse/v2/util.go +++ b/vendor/github.com/tdewolff/parse/v2/util.go @@ -397,8 +397,9 @@ var URLEncodingTable = [256]bool{ } // DataURIEncodingTable is a charmap for which characters need escaping in the Data URI encoding scheme -// Escape only non-printable characters, unicode and %, #, &. IE11 additionally requires encoding of -// \, [, ], ", <, >, `, {, }, |, ^ which is not required by Chrome, Firefox, Opera, Edge, Safari, Yandex +// Escape only non-printable characters, unicode and %, #, &. +// IE11 additionally requires encoding of \, [, ], ", <, >, `, {, }, |, ^ which is not required by Chrome, Firefox, Opera, Edge, Safari, Yandex +// To pass the HTML validator, restricted URL characters must be escaped: non-printable characters, space, <, >, #, %, " var DataURIEncodingTable = [256]bool{ // ASCII true, true, true, true, true, true, true, true, @@ -406,7 +407,7 @@ var DataURIEncodingTable = [256]bool{ true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, - false, false, true, true, false, true, true, false, // ", #, %, & + true, false, true, true, false, true, true, false, // space, ", #, %, & false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, true, false, // <, > @@ -448,15 +449,11 @@ func EncodeURL(b []byte, table [256]bool) []byte { for i := 0; i < len(b); i++ { c := b[i] if table[c] { - if c == ' ' { - b[i] = '+' - } else { - b = append(b, 0, 0) - copy(b[i+3:], b[i+1:]) - b[i+0] = '%' - b[i+1] = "0123456789ABCDEF"[c>>4] - b[i+2] = "0123456789ABCDEF"[c&15] - } + b = append(b, 0, 0) + copy(b[i+3:], b[i+1:]) + b[i+0] = '%' + b[i+1] = "0123456789ABCDEF"[c>>4] + b[i+2] = "0123456789ABCDEF"[c&15] } } return b |