Pastebin

Check-in [8bdeca9c1a]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Assume utf-8 charset for text input without explicit charset
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 8bdeca9c1a15e348f95c5a1e0902b094e92cb2ce7c0c7f8befcef28fd1ebfefd
User & Date: jef 2020-02-08 10:05:57
Context
2020-04-17
16:05
Adapt man page location Leaf check-in: 9c7f1fee65 user: jef tags: trunk
2020-02-08
10:05
Assume utf-8 charset for text input without explicit charset check-in: 8bdeca9c1a user: jef tags: trunk
2020-02-07
13:51
Update external modules check-in: e991879672 user: jef tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to mime.go.

3
4
5
6
7
8
9
10
11
12
13
14
import (
	"github.com/gabriel-vasile/mimetype"
	"strings"
)

func MimeString(data string) (mimeType string) {
	mime, _ := mimetype.DetectReader(strings.NewReader(data))
	if strings.HasPrefix(mime.String(), "text/") && !strings.Contains(mime.String(), "charset=utf-8") {
		return mime.String() + "; charset=utf-8"
	}
	return mime.String()
}







|




3
4
5
6
7
8
9
10
11
12
13
14
import (
	"github.com/gabriel-vasile/mimetype"
	"strings"
)

func MimeString(data string) (mimeType string) {
	mime, _ := mimetype.DetectReader(strings.NewReader(data))
	if strings.HasPrefix(mime.String(), "text/") && !strings.Contains(mime.String(), "charset=") {
		return mime.String() + "; charset=utf-8"
	}
	return mime.String()
}