diff options
author | Artur Malabarba <bruce.connor.am@gmail.com> | 2014-12-20 16:10:01 -0200 |
---|---|---|
committer | Artur Malabarba <bruce.connor.am@gmail.com> | 2014-12-20 16:10:01 -0200 |
commit | a56f77ba8d990e0bf0333b5b93b9cdd1bf55b33f (patch) | |
tree | 144199c14618255873f6ef5228e927ac72c195b3 /sx-request.el | |
parent | 0c380f42cf56e64d3b4446b6168fa8028760d8c5 (diff) |
Handle utf-8 encoding the right way.
Diffstat (limited to 'sx-request.el')
-rw-r--r-- | sx-request.el | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/sx-request.el b/sx-request.el index 9f2ecdb..1031ea7 100644 --- a/sx-request.el +++ b/sx-request.el @@ -136,13 +136,18 @@ the main content of the response is returned." (delete-region (point-min) (point)) (buffer-string)))) (response-zipped-p (sx-encoding-gzipped-p data)) - (data (if (not response-zipped-p) data - (if (fboundp 'zlib-decompress-region) - (zlib-decompress-region (point-min) (point-max)) - (shell-command-on-region - (point-min) (point-max) - sx-request-unzip-program nil t)) - (buffer-string))) + (data + ;; Turn string of bytes into string of characters. See + ;; http://emacs.stackexchange.com/q/4100/50 + (decode-coding-string + (if (not response-zipped-p) data + (if (fboundp 'zlib-decompress-region) + (zlib-decompress-region (point-min) (point-max)) + (shell-command-on-region + (point-min) (point-max) + sx-request-unzip-program nil t)) + (buffer-string)) + 'utf-8 'nocopy)) ;; @TODO should use `condition-case' here -- set ;; RESPONSE to 'corrupt or something (response (with-demoted-errors "`json' error: %S" |