summaryrefslogtreecommitdiff
path: root/vendor/github.com/tdewolff
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/tdewolff')
-rw-r--r--vendor/github.com/tdewolff/minify/v2/.gitignore10
-rw-r--r--vendor/github.com/tdewolff/minify/v2/Dockerfile6
-rw-r--r--vendor/github.com/tdewolff/minify/v2/Makefile4
-rw-r--r--vendor/github.com/tdewolff/minify/v2/README.md38
-rw-r--r--vendor/github.com/tdewolff/minify/v2/html/html.go6
-rw-r--r--vendor/github.com/tdewolff/minify/v2/html/table.go2
-rw-r--r--vendor/github.com/tdewolff/minify/v2/minify.go70
-rw-r--r--vendor/github.com/tdewolff/parse/v2/buffer/writer.go28
-rw-r--r--vendor/github.com/tdewolff/parse/v2/strconv/int.go20
-rw-r--r--vendor/github.com/tdewolff/parse/v2/util.go21
10 files changed, 155 insertions, 50 deletions
diff --git a/vendor/github.com/tdewolff/minify/v2/.gitignore b/vendor/github.com/tdewolff/minify/v2/.gitignore
index 8653de91d..cd340e43e 100644
--- a/vendor/github.com/tdewolff/minify/v2/.gitignore
+++ b/vendor/github.com/tdewolff/minify/v2/.gitignore
@@ -1,3 +1,4 @@
+release.sh
dist/
benchmarks/*
!benchmarks/*.go
@@ -12,3 +13,12 @@ parse/tests/*/crashers
parse/tests/*/suppressions
parse/tests/*/corpus/*
!parse/tests/*/corpus/*.*
+bindings/js/build
+bindings/js/minify.h
+bindings/js/minify.a
+bindings/js/test.min.html
+bindings/js/node_modules
+bindings/py/minify.h
+bindings/py/minify.so
+bindings/py/test.min.html
+bindings/py/tdewolff_minify.egg-info
diff --git a/vendor/github.com/tdewolff/minify/v2/Dockerfile b/vendor/github.com/tdewolff/minify/v2/Dockerfile
index 6cc2de9cc..fe3676b06 100644
--- a/vendor/github.com/tdewolff/minify/v2/Dockerfile
+++ b/vendor/github.com/tdewolff/minify/v2/Dockerfile
@@ -1,12 +1,12 @@
# Use this image to build the executable
FROM golang:1.16-alpine AS compiler
+RUN apk add --no-cache git ca-certificates make
+
WORKDIR $GOPATH/src/minify
COPY . .
-RUN apk add --update --update-cache --no-cache git ca-certificates && \
- GO111MODULES=on CGO_ENABLED=0 go build -ldflags "-s -w" -trimpath -o /bin/minify ./cmd/minify
-
+RUN /usr/bin/env bash -c make install
# Final image containing the executable from the previous step
FROM alpine:3
diff --git a/vendor/github.com/tdewolff/minify/v2/Makefile b/vendor/github.com/tdewolff/minify/v2/Makefile
index 22e448a3c..1c908800e 100644
--- a/vendor/github.com/tdewolff/minify/v2/Makefile
+++ b/vendor/github.com/tdewolff/minify/v2/Makefile
@@ -1,3 +1,4 @@
+SHELL=/usr/bin/env bash
NAME=minify
CMD=./cmd/minify
TARGETS=linux_amd64 darwin_amd64 freebsd_amd64 netbsd_amd64 openbsd_amd64 windows_amd64
@@ -17,8 +18,9 @@ release:
if [ "${.SHELLSTATUS}" -eq 0 ]; then \
echo "Releasing ${VERSION}"; \
else \
- echo "WARNING: commit is not tagged with a version"; \
+ echo "ERROR: commit is not tagged with a version"; \
echo ""; \
+ exit 1; \
fi
rm -rf dist
mkdir -p dist
diff --git a/vendor/github.com/tdewolff/minify/v2/README.md b/vendor/github.com/tdewolff/minify/v2/README.md
index 7ab6b2fe9..0f1679ba0 100644
--- a/vendor/github.com/tdewolff/minify/v2/README.md
+++ b/vendor/github.com/tdewolff/minify/v2/README.md
@@ -1,13 +1,13 @@
# Minify <a name="minify"></a> [![API reference](https://img.shields.io/badge/godoc-reference-5272B4)](https://pkg.go.dev/github.com/tdewolff/minify/v2?tab=doc) [![Go Report Card](https://goreportcard.com/badge/github.com/tdewolff/minify)](https://goreportcard.com/report/github.com/tdewolff/minify) [![codecov](https://codecov.io/gh/tdewolff/minify/branch/master/graph/badge.svg?token=Cr7r2EKPj2)](https://codecov.io/gh/tdewolff/minify) [![Donate](https://img.shields.io/badge/patreon-donate-DFB317)](https://www.patreon.com/tdewolff)
-**[Online demo](https://go.tacodewolff.nl/minify) if you need to minify files *now*.**
+**[Online demo](https://go.tacodewolff.nl/minify)** if you need to minify files *now*.
-**[Command line tool](https://github.com/tdewolff/minify/tree/master/cmd/minify) that minifies concurrently and watches file changes.**
+**[Binaries](https://github.com/tdewolff/minify/releases) of CLI for various platforms.** See [CLI](https://github.com/tdewolff/minify/tree/master/cmd/minify) for more installation instructions.
-**[Releases](https://github.com/tdewolff/minify/releases) of CLI for various platforms.** See [CLI](https://github.com/tdewolff/minify/tree/master/cmd/minify) for more installation instructions.
+**[Python bindings](https://pypi.org/project/tdewolff-minify/)** install with `pip install tdewolff-minify`
+
+**[JavaScript bindings](https://www.npmjs.com/package/tdewolff-minify)**
-**[Parse](https://github.com/tdewolff/minify/tree/master/parse) subpackage on which minify depends.**
-
---
*Did you know that the shortest valid piece of HTML5 is `<!doctype html><title>x</title>`? See for yourself at the [W3C Validator](http://validator.w3.org/)!*
@@ -600,7 +600,33 @@ func main() {
m.AddFuncRegexp(regexp.MustCompile("[/+]xml$"), xml.Minify)
fs := http.FileServer(http.Dir("www/"))
- http.Handle("/", m.Middleware(fs))
+ http.Handle("/", m.MiddlewareWithError(fs))
+}
+
+func handleError(w http.ResponseWriter, r *http.Request, err error) {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+}
+```
+
+In order to properly handle minify errors, it is necessary to close the response writer since all writes are concurrently handled. There is no need to check errors on writes since they will be returned on closing.
+
+```go
+func main() {
+ m := minify.New()
+ m.AddFunc("text/html", html.Minify)
+ m.AddFuncRegexp(regexp.MustCompile("^(application|text)/(x-)?(java|ecma)script$"), js.Minify)
+
+ input := `<script>const i = 1_000_</script>` // Faulty JS
+ req := httptest.NewRequest(http.MethodGet, "/", nil)
+ rec := httptest.NewRecorder()
+ m.Middleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "text/html")
+ _, _ = w.Write([]byte(input))
+
+ if err = w.(io.Closer).Close(); err != nil {
+ panic(err)
+ }
+ })).ServeHTTP(rec, req)
}
```
diff --git a/vendor/github.com/tdewolff/minify/v2/html/html.go b/vendor/github.com/tdewolff/minify/v2/html/html.go
index 8342f72a8..6868c9b79 100644
--- a/vendor/github.com/tdewolff/minify/v2/html/html.go
+++ b/vendor/github.com/tdewolff/minify/v2/html/html.go
@@ -274,10 +274,10 @@ func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]st
}
}
- if o.KeepWhitespace || t.Traits&objectTag != 0 {
- omitSpace = false
- } else if t.Traits&nonPhrasingTag != 0 {
+ if t.Traits&nonPhrasingTag != 0 {
omitSpace = true // omit spaces after block elements
+ } else if o.KeepWhitespace || t.Traits&objectTag != 0 {
+ omitSpace = false
}
if !omitEndTag {
diff --git a/vendor/github.com/tdewolff/minify/v2/html/table.go b/vendor/github.com/tdewolff/minify/v2/html/table.go
index 5de3b497f..1ace143a5 100644
--- a/vendor/github.com/tdewolff/minify/v2/html/table.go
+++ b/vendor/github.com/tdewolff/minify/v2/html/table.go
@@ -35,7 +35,7 @@ var tagMap = map[Hash]traits{
Body: nonPhrasingTag,
Br: nonPhrasingTag,
Button: objectTag,
- Canvas: objectTag,
+ Canvas: objectTag | keepPTag,
Caption: nonPhrasingTag,
Cite: normalTag,
Code: normalTag,
diff --git a/vendor/github.com/tdewolff/minify/v2/minify.go b/vendor/github.com/tdewolff/minify/v2/minify.go
index db013ccfe..db747e397 100644
--- a/vendor/github.com/tdewolff/minify/v2/minify.go
+++ b/vendor/github.com/tdewolff/minify/v2/minify.go
@@ -28,6 +28,9 @@ var Warning = log.New(os.Stderr, "WARNING: ", 0)
// ErrNotExist is returned when no minifier exists for a given mimetype.
var ErrNotExist = errors.New("minifier does not exist for mimetype")
+// ErrClosedWriter is returned when writing to a closed writer.
+var ErrClosedWriter = errors.New("write on closed writer")
+
////////////////////////////////////////////////////////////////
// MinifierFunc is a function that implements Minifer.
@@ -248,37 +251,47 @@ func (m *M) Reader(mediatype string, r io.Reader) io.Reader {
return pr
}
-// minifyWriter makes sure that errors from the minifier are passed down through Close (can be blocking).
-type minifyWriter struct {
- pw *io.PipeWriter
- wg sync.WaitGroup
- err error
+// writer makes sure that errors from the minifier are passed down through Close (can be blocking).
+type writer struct {
+ pw *io.PipeWriter
+ wg sync.WaitGroup
+ err error
+ closed bool
}
// Write intercepts any writes to the writer.
-func (w *minifyWriter) Write(b []byte) (int, error) {
- return w.pw.Write(b)
+func (w *writer) Write(b []byte) (int, error) {
+ if w.closed {
+ return 0, ErrClosedWriter
+ }
+ n, err := w.pw.Write(b)
+ if w.err != nil {
+ err = w.err
+ }
+ return n, err
}
// Close must be called when writing has finished. It returns the error from the minifier.
-func (w *minifyWriter) Close() error {
- w.pw.Close()
- w.wg.Wait()
+func (w *writer) Close() error {
+ if !w.closed {
+ w.pw.Close()
+ w.wg.Wait()
+ w.closed = true
+ }
return w.err
}
// Writer wraps a Writer interface and minifies the stream.
// Errors from the minifier are returned by Close on the writer.
// The writer must be closed explicitly.
-func (m *M) Writer(mediatype string, w io.Writer) *minifyWriter {
+func (m *M) Writer(mediatype string, w io.Writer) *writer {
pr, pw := io.Pipe()
- mw := &minifyWriter{pw, sync.WaitGroup{}, nil}
+ mw := &writer{pw, sync.WaitGroup{}, nil, false}
mw.wg.Add(1)
go func() {
defer mw.wg.Done()
if err := m.Minify(mediatype, w, pr); err != nil {
- io.Copy(w, pr)
mw.err = err
}
pr.Close()
@@ -286,26 +299,26 @@ func (m *M) Writer(mediatype string, w io.Writer) *minifyWriter {
return mw
}
-// minifyResponseWriter wraps an http.ResponseWriter and makes sure that errors from the minifier are passed down through Close (can be blocking).
+// responseWriter wraps an http.ResponseWriter and makes sure that errors from the minifier are passed down through Close (can be blocking).
// All writes to the response writer are intercepted and minified on the fly.
// http.ResponseWriter loses all functionality such as Pusher, Hijacker, Flusher, ...
-type minifyResponseWriter struct {
+type responseWriter struct {
http.ResponseWriter
- writer *minifyWriter
+ writer *writer
m *M
mediatype string
}
// WriteHeader intercepts any header writes and removes the Content-Length header.
-func (w *minifyResponseWriter) WriteHeader(status int) {
+func (w *responseWriter) WriteHeader(status int) {
w.ResponseWriter.Header().Del("Content-Length")
w.ResponseWriter.WriteHeader(status)
}
// Write intercepts any writes to the response writer.
// The first write will extract the Content-Type as the mediatype. Otherwise it falls back to the RequestURI extension.
-func (w *minifyResponseWriter) Write(b []byte) (int, error) {
+func (w *responseWriter) Write(b []byte) (int, error) {
if w.writer == nil {
// first write
if mediatype := w.ResponseWriter.Header().Get("Content-Type"); mediatype != "" {
@@ -317,7 +330,7 @@ func (w *minifyResponseWriter) Write(b []byte) (int, error) {
}
// Close must be called when writing has finished. It returns the error from the minifier.
-func (w *minifyResponseWriter) Close() error {
+func (w *responseWriter) Close() error {
if w.writer != nil {
return w.writer.Close()
}
@@ -327,9 +340,9 @@ func (w *minifyResponseWriter) Close() error {
// ResponseWriter minifies any writes to the http.ResponseWriter.
// http.ResponseWriter loses all functionality such as Pusher, Hijacker, Flusher, ...
// Minification might be slower than just sending the original file! Caching is advised.
-func (m *M) ResponseWriter(w http.ResponseWriter, r *http.Request) *minifyResponseWriter {
+func (m *M) ResponseWriter(w http.ResponseWriter, r *http.Request) *responseWriter {
mediatype := mime.TypeByExtension(path.Ext(r.RequestURI))
- return &minifyResponseWriter{w, nil, m, mediatype}
+ return &responseWriter{w, nil, m, mediatype}
}
// Middleware provides a middleware function that minifies content on the fly by intercepting writes to http.ResponseWriter.
@@ -338,8 +351,21 @@ func (m *M) ResponseWriter(w http.ResponseWriter, r *http.Request) *minifyRespon
func (m *M) Middleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
mw := m.ResponseWriter(w, r)
- defer mw.Close()
+ next.ServeHTTP(mw, r)
+ mw.Close()
+ })
+}
+// MiddlewareWithError provides a middleware function that minifies content on the fly by intercepting writes to http.ResponseWriter. The error function allows handling minification errors.
+// http.ResponseWriter loses all functionality such as Pusher, Hijacker, Flusher, ...
+// Minification might be slower than just sending the original file! Caching is advised.
+func (m *M) MiddlewareWithError(next http.Handler, errorFunc func(w http.ResponseWriter, r *http.Request, err error)) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ mw := m.ResponseWriter(w, r)
next.ServeHTTP(mw, r)
+ if err := mw.Close(); err != nil {
+ errorFunc(w, r, err)
+ return
+ }
})
}
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