Repository: gohugoio/hugo (language: go)

Issue:
hugo --minify breaks URL encoded
Hi HuGophers,

### What version of Hugo are you using (`hugo version`)?
<pre>
$ hugo version
hugo v0.96.0 linux/amd64 BuildDate=unknown
</pre>
Build with `go install github.com/gohugoio/hugo@latest` 5 mn ago.

### Trouble
In my template, I use emoji with rel="icon". To do that, I use URL encoded SVG format (for w3c validation)
```html
<link rel="icon" href="data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220%200%20100%20100%22%3E%3Ctext%20y=%22.9em%22%20font-size=%2290%22%3E💾%3C/text%3E%3C/svg%3E" />
```

But, with `--minify flag, every space `%20` are converted to space
```html
<link rel=icon href="data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22%3E%3Ctext y=%22.9em%22 font-size=%2290%22%3E%F0%9F%92%BE%3C/text%3E%3C/svg%3E">
```


Discussion / hints:
See <https://github.com/tdewolff/minify/issues/475>
Thanks for raising this issue. Unfortunately, the specification isn't clear about which characters should be URL encoded and which not, and it wildly depends on the browser's implementation. The current encoding (where spaces are not encoded) was tested with all major browsers, but perhaps we missed one. For which renderer/browser does this cause an issue for you? Just now testing in Firefox and Chrome it seems to work fine.
I didn't have any problems rendering the minified HTML. The problem is that it doesn't validate with `https://validator.w3.org/`.

> Unfortunately, the specification isn't clear about which characters should be URL encoded and which not,

 I understand.

I thought I could work around the ambiguity by base64 encoding, but minify determines that (in this case) base64 encoding produces a longer string, and reverts to plain text.

Fix patch:
diff --git a/docs/data/docs.json b/docs/data/docs.json
index 2440fc930de..ddd9e12469b 100644
--- a/docs/data/docs.json
+++ b/docs/data/docs.json
@@ -1860,6 +1860,7 @@
           "keepNumbers": false
         },
         "svg": {
+          "keepComments": false,
           "precision": 0
         },
         "xml": {
@@ -4665,6 +4666,12 @@
           ],
           "Examples": []
         },
+        "ByType": {
+          "Description": "",
+          "Args": null,
+          "Aliases": null,
+          "Examples": null
+        },
         "Concat": {
           "Description": "",
           "Args": null,
@@ -4694,7 +4701,7 @@
           "Examples": null
         },
         "Get": {
-          "Description": "Get locates the filename given in Hugo's assets filesystem and\ncreates a Resource object that can be used for\nfurther transformations.",
+          "Description": "Get locates the filename given in Hugo's assets filesystem\nand creates a Resource object that can be used for further transformations.",
           "Args": [
             "filename"
           ],
@@ -4862,6 +4869,12 @@
           "Aliases": null,
           "Examples": null
         },
+        "Current": {
+          "Description": "",
+          "Args": null,
+          "Aliases": null,
+          "Examples": null
+        },
         "Data": {
           "Description": "",
           "Args": null,
diff --git a/go.mod b/go.mod
index a4308ae6999..b7202f686bd 100644
--- a/go.mod
+++ b/go.mod
@@ -12,6 +12,7 @@ require (
 	github.com/bep/godartsass v0.14.0
 	github.com/bep/golibsass v1.0.0
 	github.com/bep/gowebp v0.1.0
+	github.com/bep/overlayfs v0.1.0
 	github.com/bep/tmc v0.5.1
 	github.com/clbanning/mxj/v2 v2.5.5
 	github.com/cli/safeexec v1.0.0
@@ -54,7 +55,7 @@ require (
 	github.com/spf13/fsync v0.9.0
 	github.com/spf13/jwalterweatherman v1.1.0
 	github.com/spf13/pflag v1.0.5
-	github.com/tdewolff/minify/v2 v2.10.0
+	github.com/tdewolff/minify/v2 v2.11.0
 	github.com/yuin/goldmark v1.4.11
 	go.uber.org/atomic v1.9.0
 	gocloud.dev v0.25.0
@@ -98,7 +99,6 @@ require (
 	github.com/aws/aws-sdk-go-v2/service/sso v1.11.3 // indirect
 	github.com/aws/aws-sdk-go-v2/service/sts v1.16.3 // indirect
 	github.com/aws/smithy-go v1.11.2 // indirect
-	github.com/bep/overlayfs v0.1.0 // indirect
 	github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
 	github.com/dlclark/regexp2 v1.4.0 // indirect
 	github.com/go-openapi/jsonpointer v0.19.5 // indirect
@@ -118,7 +118,7 @@ require (
 	github.com/mattn/go-runewidth v0.0.9 // indirect
 	github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
 	github.com/russross/blackfriday/v2 v2.1.0 // indirect
-	github.com/tdewolff/parse/v2 v2.5.27 // indirect
+	github.com/tdewolff/parse/v2 v2.5.28 // indirect
 	go.opencensus.io v0.23.0 // indirect
 	golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29 // indirect
 	golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a // indirect
diff --git a/go.sum b/go.sum
index 0caef4d6604..59f3b1365d0 100644
--- a/go.sum
+++ b/go.sum
@@ -564,8 +564,6 @@ github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMB
 github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
 github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
 github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
-github.com/spf13/afero v1.8.1 h1:izYHOT71f9iZ7iq37Uqjael60/vYC6vMtzedudZ0zEk=
-github.com/spf13/afero v1.8.1/go.mod h1:CtAatgMJh6bJEIs48Ay/FOnkljP3WeGUG0MC1RfAqwo=
 github.com/spf13/afero v1.8.2 h1:xehSyVa0YnHWsJ49JFljMpg1HX19V6NDZ1fkm1Xznbo=
 github.com/spf13/afero v1.8.2/go.mod h1:CtAatgMJh6bJEIs48Ay/FOnkljP3WeGUG0MC1RfAqwo=
 github.com/spf13/cast v1.4.1 h1:s0hze+J0196ZfEMTs80N7UlFt0BDuQ7Q+JDnHiMWKdA=
@@ -590,10 +588,10 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
 github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 github.com/stretchr/testify v1.7.1-0.20210427113832-6241f9ab9942 h1:t0lM6y/M5IiUZyvbBTcngso8SZEZICH7is9B6g/obVU=
 github.com/stretchr/testify v1.7.1-0.20210427113832-6241f9ab9942/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
-github.com/tdewolff/minify/v2 v2.10.0 h1:ovVAHUcjfGrBDf1EIvsodRUVJiZK/28mMose08B7k14=
-github.com/tdewolff/minify/v2 v2.10.0/go.mod h1:6XAjcHM46pFcRE0eztigFPm0Q+Cxsw8YhEWT+rDkcZM=
-github.com/tdewolff/parse/v2 v2.5.27 h1:PL3LzzXaOpmdrknnOlIeO2muIBHAwiKp6TxN1RbU5gI=
-github.com/tdewolff/parse/v2 v2.5.27/go.mod h1:WzaJpRSbwq++EIQHYIRTpbYKNA3gn9it1Ik++q4zyho=
+github.com/tdewolff/minify/v2 v2.11.0 h1:cl7b3a1N3v1I+gQThz6sTDKkkODWNblcEy3DGhVhZrM=
+github.com/tdewolff/minify/v2 v2.11.0/go.mod h1:UkCTT2Sa8N7XNU0Z9Q+De6NvaxPlC7DGfSWDRowwXqY=
+github.com/tdewolff/parse/v2 v2.5.28 h1:QziFVLe+bfFIwnCWAJzMrzwltQXPT21Evl9Z4x25D+U=
+github.com/tdewolff/parse/v2 v2.5.28/go.mod h1:WzaJpRSbwq++EIQHYIRTpbYKNA3gn9it1Ik++q4zyho=
 github.com/tdewolff/test v1.0.6 h1:76mzYJQ83Op284kMT+63iCNCI7NEERsIN8dLM+RiKr4=
 github.com/tdewolff/test v1.0.6/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE=
 github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
diff --git a/minifiers/config.go b/minifiers/config.go
index 135e39b86dd..233f53c2717 100644
--- a/minifiers/config.go
+++ b/minifiers/config.go
@@ -44,7 +44,8 @@ var defaultTdewolffConfig = tdewolffConfig{
 	JS:   js.Minifier{},
 	JSON: json.Minifier{},
 	SVG: svg.Minifier{
-		Precision: 0,
+		KeepComments: false,
+		Precision:    0,
 	},
 	XML: xml.Minifier{
 		KeepWhitespace: false,


Test patch: