shithub: mycel

Download patch

ref: ee3bf06b2d047bea9a3c06253f1b652f578afa6c
parent: 99ad10d49938ebfcfd65d45dec428078e8d10fbb
author: Philip Silva <philip.silva@protonmail.com>
date: Fri Apr 23 08:10:06 EDT 2021

Handle more encodings

- basically all that are in
  golang.org/x/text/encoding/ianaindex

--- a/opossum.go
+++ b/opossum.go
@@ -2,7 +2,7 @@
 
 import (
 	"bytes"
-	"golang.org/x/text/encoding/charmap"
+	"golang.org/x/text/encoding/ianaindex"
 	"io/ioutil"
 	"mime"
 	"github.com/psilva261/opossum/logger"
@@ -89,16 +89,20 @@
 	if !ok || charset == "utf8" || charset == "utf-8" {
 		return buf
 	}
-	if strings.ToLower(charset) == "iso-8859-1" {
-		r := bytes.NewReader(buf)
-		cr := charmap.ISO8859_1.NewDecoder().Reader(r)
+	e, err := ianaindex.IANA.Encoding(charset)
+	if err != nil {
+		log.Errorf("get encoding %v: %v", charset, err)
+		return buf
+	}
+	r := bytes.NewReader(buf)
+	cr := e.NewDecoder().Reader(r)
 
-		updated, err := ioutil.ReadAll(cr)
-		if err == nil {
-			buf = updated
-		} else {
-			log.Errorf("utf8: unable to decode to %v: %v", charset, err)
-		}
+	updated, err := ioutil.ReadAll(cr)
+	if err == nil {
+		buf = updated
+	} else {
+		log.Errorf("utf8: unable to decode to %v: %v", charset, err)
 	}
+
 	return buf
 }
\ No newline at end of file