about summary refs log tree commit diff stats
path: root/src/loader/response.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-09-27 03:07:52 +0200
committerbptato <nincsnevem662@gmail.com>2023-09-27 03:07:52 +0200
commit7724082d68c452064025fa30c1c0c0127f936621 (patch)
treef922181735509d2ec066cb71e523fb6bd1757b78 /src/loader/response.nim
parent14baa050d3ab4e45879582a8f87eeb1e42407909 (diff)
downloadchawan-7724082d68c452064025fa30c1c0c0127f936621.tar.gz
Response.text: assume utf-8
Diffstat (limited to 'src/loader/response.nim')
-rw-r--r--src/loader/response.nim10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/loader/response.nim b/src/loader/response.nim
index 2be709c7..92aa5c7a 100644
--- a/src/loader/response.nim
+++ b/src/loader/response.nim
@@ -65,14 +65,14 @@ proc text*(response: Response): Promise[JSResult[string]] {.jsfunc.} =
   let bodyRead = response.bodyRead
   response.bodyRead = nil
   return bodyRead.then(proc(s: string): JSResult[string] =
-    if response.charset == CHARSET_UTF_8 and s.validateUtf8() == -1:
+    let cs = if response.charset == CHARSET_UNKNOWN:
+      CHARSET_UTF_8
+    else:
+      response.charset
+    if cs == CHARSET_UTF_8 and s.validateUtf8() == -1:
       ok(s)
     else:
       let ss = newStringStream(s)
-      let cs = if response.charset == CHARSET_UNKNOWN:
-        CHARSET_UTF_8
-      else:
-        response.charset
       let ds = newDecoderStream(ss, cs)
       let es = newEncoderStream(ds, CHARSET_UTF_8)
       return ok(es.readAll())