diff --git a/go.mod b/go.mod index 9a3d8db2c..aa65072ce 100644 --- a/go.mod +++ b/go.mod @@ -46,7 +46,7 @@ require ( github.com/superseriousbusiness/activity v1.4.0-gts github.com/superseriousbusiness/exif-terminator v0.5.0 github.com/superseriousbusiness/oauth2/v4 v4.3.2-SSB.0.20230227143000-f4900831d6c8 - github.com/tdewolff/minify/v2 v2.19.10 + github.com/tdewolff/minify/v2 v2.20.0 github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80 github.com/ulule/limiter/v3 v3.11.2 github.com/uptrace/bun v1.1.16 @@ -151,7 +151,7 @@ require ( github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.4.2 // indirect github.com/superseriousbusiness/go-jpeg-image-structure/v2 v2.0.0-20220321154430-d89a106fdabe // indirect - github.com/tdewolff/parse/v2 v2.6.8 // indirect + github.com/tdewolff/parse/v2 v2.7.0 // indirect github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect diff --git a/go.sum b/go.sum index 99d227124..0638c4ccf 100644 --- a/go.sum +++ b/go.sum @@ -501,12 +501,12 @@ github.com/superseriousbusiness/go-jpeg-image-structure/v2 v2.0.0-20220321154430 github.com/superseriousbusiness/go-jpeg-image-structure/v2 v2.0.0-20220321154430-d89a106fdabe/go.mod h1:gH4P6gN1V+wmIw5o97KGaa1RgXB/tVpC2UNzijhg3E4= github.com/superseriousbusiness/oauth2/v4 v4.3.2-SSB.0.20230227143000-f4900831d6c8 h1:nTIhuP157oOFcscuoK1kCme1xTeGIzztSw70lX9NrDQ= github.com/superseriousbusiness/oauth2/v4 v4.3.2-SSB.0.20230227143000-f4900831d6c8/go.mod h1:uYC/W92oVRJ49Vh1GcvTqpeFqHi+Ovrl2sMllQWRAEo= -github.com/tdewolff/minify/v2 v2.19.10 h1:79Z2DJ9p0zSBj2BxD5fyLkIwhhRZnWSOeK3C52ljAu4= -github.com/tdewolff/minify/v2 v2.19.10/go.mod h1:IX+vt5HNKc+RFIQj7aI4D6RQ9p41vjay9lGorpHNC34= -github.com/tdewolff/parse/v2 v2.6.8 h1:mhNZXYCx//xG7Yq2e/kVLNZw4YfYmeHbhx+Zc0OvFMA= -github.com/tdewolff/parse/v2 v2.6.8/go.mod h1:XHDhaU6IBgsryfdnpzUXBlT6leW/l25yrFBTEb4eIyM= -github.com/tdewolff/test v1.0.9 h1:SswqJCmeN4B+9gEAi/5uqT0qpi1y2/2O47V/1hhGZT0= -github.com/tdewolff/test v1.0.9/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE= +github.com/tdewolff/minify/v2 v2.20.0 h1:JFoL/Jxnyebf/jw3woqpmwBjSNJYSeU+sTFl9dTMHQ8= +github.com/tdewolff/minify/v2 v2.20.0/go.mod h1:TEE9CWftBwKQLUTZHuH9upjiqlt8zFpQOGxQ81rsG3c= +github.com/tdewolff/parse/v2 v2.7.0 h1:eVeKTV9nQ9BNS0LPlOgrhLXisiAjacaf60aRgSEtnic= +github.com/tdewolff/parse/v2 v2.7.0/go.mod h1:9p2qMIHpjRSTr1qnFxQr+igogyTUTlwvf9awHSm84h8= +github.com/tdewolff/test v1.0.10 h1:uWiheaLgLcNFqHcdWveum7PQfMnIUTf9Kl3bFxrIoew= +github.com/tdewolff/test v1.0.10/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE= github.com/tidwall/btree v0.0.0-20191029221954-400434d76274 h1:G6Z6HvJuPjG6XfNGi/feOATzeJrfgTNJY+rGrHbA04E= github.com/tidwall/btree v0.0.0-20191029221954-400434d76274/go.mod h1:huei1BkDWJ3/sLXmO+bsCNELL+Bp2Kks9OLyQFkzvA8= github.com/tidwall/buntdb v1.1.2 h1:noCrqQXL9EKMtcdwJcmuVKSEjqu1ua99RHHgbLTEHRo= diff --git a/vendor/github.com/tdewolff/minify/v2/.gitignore b/vendor/github.com/tdewolff/minify/v2/.gitignore index c9ea38dbc..e2cf6cf8e 100644 --- a/vendor/github.com/tdewolff/minify/v2/.gitignore +++ b/vendor/github.com/tdewolff/minify/v2/.gitignore @@ -23,8 +23,10 @@ bindings/js/example/node_modules bindings/js/example/test.min.html bindings/py/go.mod bindings/py/go.sum -bindings/py/minify.h -bindings/py/minify.so -bindings/py/tdewolff_minify.egg-info +bindings/py/**/*.h +bindings/py/**/*.so +bindings/py/**/*.egg-info bindings/py/example/example.min.html bindings/py/dist +bindings/py/build +bindings/py/**/*.pyc diff --git a/vendor/github.com/tdewolff/parse/v2/html/lex.go b/vendor/github.com/tdewolff/parse/v2/html/lex.go index 4325024bd..5619ce9e7 100644 --- a/vendor/github.com/tdewolff/parse/v2/html/lex.go +++ b/vendor/github.com/tdewolff/parse/v2/html/lex.go @@ -449,7 +449,7 @@ func (l *Lexer) shiftXML(rawTag Hash) []byte { } } else if c == 0 { if l.r.Err() == nil { - l.err = parse.NewErrorLexer(l.r, "HTML parse error: unexpected NULL character") + l.err = parse.NewErrorLexer(l.r, "unexpected NULL character") } return l.r.Shift() } else { @@ -464,7 +464,7 @@ func (l *Lexer) shiftXML(rawTag Hash) []byte { break } else if c == 0 { if l.r.Err() == nil { - l.err = parse.NewErrorLexer(l.r, "HTML parse error: unexpected NULL character") + l.err = parse.NewErrorLexer(l.r, "unexpected NULL character") } return l.r.Shift() } diff --git a/vendor/github.com/tdewolff/parse/v2/strconv/decimal.go b/vendor/github.com/tdewolff/parse/v2/strconv/decimal.go index fc3baf608..8427cb4ac 100644 --- a/vendor/github.com/tdewolff/parse/v2/strconv/decimal.go +++ b/vendor/github.com/tdewolff/parse/v2/strconv/decimal.go @@ -4,60 +4,69 @@ import ( "math" ) +// ParseDecimal parses number of the format 1.2 func ParseDecimal(b []byte) (float64, int) { + // float64 has up to 17 significant decimal digits and an exponent in [-1022,1023] i := 0 - start := i + //sign := 1.0 + //if 0 < len(b) && b[0] == '-' { + // sign = -1.0 + // i++ + //} + + start := -1 dot := -1 - trunk := -1 n := uint64(0) for ; i < len(b); i++ { + // parse up to 18 significant digits (with dot will be 17) ignoring zeros before/after c := b[i] if '0' <= c && c <= '9' { - if trunk == -1 { - if math.MaxUint64/10 < n { - trunk = i - } else { - n *= 10 - n += uint64(c - '0') + if start == -1 { + if '1' <= c && c <= '9' { + n = uint64(c - '0') + start = i } + } else if i-start < 18 { + n *= 10 + n += uint64(c - '0') + } + } else if c == '.' { + if dot != -1 { + break } - } else if dot == -1 && c == '.' { dot = i } else { break } } - if i == start || i == start+1 && dot == start { - return 0.0, 0 + if i == 1 && dot == 0 { + return 0.0, 0 // only dot + } else if start == -1 { + return 0.0, i // only zeros and dot + } else if dot == -1 { + dot = i } - f := float64(n) - mantExp := int64(0) - if dot != -1 { - if trunk == -1 { - trunk = i - } - mantExp = int64(trunk - dot - 1) - } else if trunk != -1 { - mantExp = int64(trunk - i) + exp := (dot - start) - LenUint(n) + if dot < start { + exp++ + } + if 1023 < exp { + return math.Inf(1), i + //if sign == 1.0 { + // return math.Inf(1), i + //} else { + // return math.Inf(-1), i + //} + } else if exp < -1022 { + return 0.0, i } - exp := -mantExp - // copied from strconv/atof.go - if exp == 0 { - return f, i - } else if 0 < exp && exp <= 15+22 { // int * 10^k - // If exponent is big but number of digits is not, - // can move a few zeros into the integer part. - if 22 < exp { - f *= float64pow10[exp-22] - exp = 22 - } - if -1e15 <= f && f <= 1e15 { - return f * float64pow10[exp], i - } - } else if exp < 0 && -22 <= exp { // int / 10^k - return f / float64pow10[-exp], i + f := float64(n) // sign * float64(n) + if 0 <= exp && exp < 23 { + return f * float64pow10[exp], i + } else if 23 < exp && exp < 0 { + return f / float64pow10[exp], i } - return f * math.Pow10(int(-mantExp)), i + return f * math.Pow10(exp), i } diff --git a/vendor/github.com/tdewolff/parse/v2/strconv/int.go b/vendor/github.com/tdewolff/parse/v2/strconv/int.go index e3483bd3a..2f45d1e21 100644 --- a/vendor/github.com/tdewolff/parse/v2/strconv/int.go +++ b/vendor/github.com/tdewolff/parse/v2/strconv/int.go @@ -17,9 +17,10 @@ func ParseInt(b []byte) (int64, int) { n := uint64(0) for i < len(b) { c := b[i] - if n > math.MaxUint64/10 { - return 0, 0 - } else if c >= '0' && c <= '9' { + if '0' <= c && c <= '9' { + if uint64(-math.MinInt64)/10 < n || uint64(-math.MinInt64)-uint64(c-'0') < n*10 { + return 0, 0 + } n *= 10 n += uint64(c - '0') } else { @@ -30,7 +31,7 @@ func ParseInt(b []byte) (int64, int) { if i == start { return 0, 0 } - if !neg && n > uint64(math.MaxInt64) || n > uint64(math.MaxInt64)+1 { + if !neg && uint64(math.MaxInt64) < n { return 0, 0 } else if neg { return -int64(n), i @@ -45,9 +46,10 @@ func ParseUint(b []byte) (uint64, int) { n := uint64(0) for i < len(b) { c := b[i] - if n > math.MaxUint64/10 { - return 0, 0 - } else if c >= '0' && c <= '9' { + if '0' <= c && c <= '9' { + if math.MaxUint64/10 < n || math.MaxUint64-uint64(c-'0') < n*10 { + return 0, 0 + } n *= 10 n += uint64(c - '0') } else { @@ -66,6 +68,10 @@ func LenInt(i int64) int { } i = -i } + return LenUint(uint64(i)) +} + +func LenUint(i uint64) int { switch { case i < 10: return 1 @@ -103,6 +109,8 @@ func LenInt(i int64) int { return 17 case i < 1000000000000000000: return 18 + case i < 10000000000000000000: + return 19 } - return 19 + return 20 } diff --git a/vendor/github.com/tdewolff/parse/v2/strconv/number.go b/vendor/github.com/tdewolff/parse/v2/strconv/number.go new file mode 100644 index 000000000..9f768dbdb --- /dev/null +++ b/vendor/github.com/tdewolff/parse/v2/strconv/number.go @@ -0,0 +1,125 @@ +package strconv + +import ( + "math" + "unicode/utf8" +) + +// ParseNumber parses a byte-slice and returns the number it represents and the amount of decimals. +// If an invalid character is encountered, it will stop there. +func ParseNumber(b []byte, groupSym rune, decSym rune) (int64, int, int) { + n, dec := 0, 0 + sign := int64(1) + price := int64(0) + hasDecimals := false + if 0 < len(b) && b[0] == '-' { + sign = -1 + n++ + } + for n < len(b) { + if '0' <= b[n] && b[n] <= '9' { + digit := sign * int64(b[n]-'0') + if sign == 1 && (math.MaxInt64/10 < price || math.MaxInt64-digit < price*10) { + break + } else if sign == -1 && (price < math.MinInt64/10 || price*10 < math.MinInt64-digit) { + break + } + price *= 10 + price += digit + if hasDecimals { + dec++ + } + n++ + } else if r, size := utf8.DecodeRune(b[n:]); !hasDecimals && (r == groupSym || r == decSym) { + if r == decSym { + hasDecimals = true + } + n += size + } else { + break + } + } + return price, dec, n +} + +// AppendNumber will append an int64 formatted as a number with the given number of decimal digits. +func AppendNumber(b []byte, price int64, dec int, groupSize int, groupSym rune, decSym rune) []byte { + if dec < 0 { + dec = 0 + } + if utf8.RuneLen(groupSym) == -1 { + groupSym = '.' + } + if utf8.RuneLen(decSym) == -1 { + decSym = ',' + } + + sign := int64(1) + if price < 0 { + sign = -1 + } + + // calculate size + n := LenInt(price) + if dec < n && 0 < groupSize && groupSym != 0 { + n += utf8.RuneLen(groupSym) * (n - dec - 1) / groupSize + } + if 0 < dec { + if n <= dec { + n = 1 + dec // zero and decimals + } + n += utf8.RuneLen(decSym) + } + if sign == -1 { + n++ + } + + // resize byte slice + i := len(b) + if cap(b) < i+n { + b = append(b, make([]byte, n)...) + } else { + b = b[:i+n] + } + + // print fractional-part + i += n - 1 + if 0 < dec { + for 0 < dec { + c := byte(sign*(price%10)) + '0' + price /= 10 + b[i] = c + dec-- + i-- + } + i -= utf8.RuneLen(decSym) + utf8.EncodeRune(b[i+1:], decSym) + } + + // print integer-part + if price == 0 { + b[i] = '0' + if sign == -1 { + b[i-1] = '-' + } + return b + } + j := 0 + for price != 0 { + if 0 < groupSize && groupSym != 0 && 0 < j && j%groupSize == 0 { + i -= utf8.RuneLen(groupSym) + utf8.EncodeRune(b[i+1:], groupSym) + } + + c := byte(sign*(price%10)) + '0' + price /= 10 + b[i] = c + i-- + j++ + } + + if sign == -1 { + b[i] = '-' + } + return b +} diff --git a/vendor/github.com/tdewolff/parse/v2/strconv/price.go b/vendor/github.com/tdewolff/parse/v2/strconv/price.go deleted file mode 100644 index 18ded69f5..000000000 --- a/vendor/github.com/tdewolff/parse/v2/strconv/price.go +++ /dev/null @@ -1,83 +0,0 @@ -package strconv - -// AppendPrice will append an int64 formatted as a price, where the int64 is the price in cents. -// It does not display whether a price is negative or not. -func AppendPrice(b []byte, price int64, dec bool, milSeparator byte, decSeparator byte) []byte { - if price < 0 { - if price == -9223372036854775808 { - x := []byte("92 233 720 368 547 758 08") - x[2] = milSeparator - x[6] = milSeparator - x[10] = milSeparator - x[14] = milSeparator - x[18] = milSeparator - x[22] = decSeparator - return append(b, x...) - } - price = -price - } - - // rounding - if !dec { - firstDec := (price / 10) % 10 - if 5 <= firstDec { - price += 100 - } - } - - // calculate size - n := LenInt(price) - 2 - if 0 < n { - n += (n - 1) / 3 // mil separator - } else { - n = 1 - } - if dec { - n += 2 + 1 // decimals + dec separator - } - - // resize byte slice - i := len(b) - if cap(b) < i+n { - b = append(b, make([]byte, n)...) - } else { - b = b[:i+n] - } - - // print fractional-part - i += n - 1 - if dec { - for j := 0; j < 2; j++ { - c := byte(price%10) + '0' - price /= 10 - b[i] = c - i-- - } - b[i] = decSeparator - i-- - } else { - price /= 100 - } - - if price == 0 { - b[i] = '0' - return b - } - - // print integer-part - j := 0 - for 0 < price { - if j == 3 { - b[i] = milSeparator - i-- - j = 0 - } - - c := byte(price%10) + '0' - price /= 10 - b[i] = c - i-- - j++ - } - return b -} diff --git a/vendor/modules.txt b/vendor/modules.txt index c7769b80e..04bf790ca 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -646,11 +646,11 @@ github.com/superseriousbusiness/oauth2/v4/generates github.com/superseriousbusiness/oauth2/v4/manage github.com/superseriousbusiness/oauth2/v4/models github.com/superseriousbusiness/oauth2/v4/server -# github.com/tdewolff/minify/v2 v2.19.10 +# github.com/tdewolff/minify/v2 v2.20.0 ## explicit; go 1.18 github.com/tdewolff/minify/v2 github.com/tdewolff/minify/v2/html -# github.com/tdewolff/parse/v2 v2.6.8 +# github.com/tdewolff/parse/v2 v2.7.0 ## explicit; go 1.13 github.com/tdewolff/parse/v2 github.com/tdewolff/parse/v2/buffer