Charset detection heuristics added with chardet lib.

This commit is contained in:
Musab Gültekin
2019-07-03 18:08:28 +03:00
parent b355a566cf
commit 33238bc875
7 changed files with 90 additions and 35 deletions

View File

@@ -13,7 +13,6 @@ import (
"net/http"
"net/http/httptest"
"testing"
"unicode/utf8"
)
func TestSimple(t *testing.T) {
@@ -175,33 +174,6 @@ func TestExtractor(t *testing.T) {
}).Start()
}
func TestCharsetDetection(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "\xf0ültekin")
}))
defer ts.Close()
geziyor.NewGeziyor(&geziyor.Options{
StartURLs: []string{ts.URL},
ParseFunc: func(g *geziyor.Geziyor, r *client.Response) {
if !utf8.Valid(r.Body) {
t.Fatal()
}
},
CharsetDetectDisabled: false,
}).Start()
geziyor.NewGeziyor(&geziyor.Options{
StartURLs: []string{ts.URL},
ParseFunc: func(g *geziyor.Geziyor, r *client.Response) {
if utf8.Valid(r.Body) {
t.Fatal()
}
},
CharsetDetectDisabled: true,
}).Start()
}
func TestRedirect(t *testing.T) {
defer leaktest.Check(t)()
geziyor.NewGeziyor(&geziyor.Options{