ljos / sparql-mode

A SPARQL mode for emacs
GNU General Public License v3.0
62 stars 23 forks source link

UTF-8 results #69

Open johanwk opened 3 years ago

johanwk commented 3 years ago

I'm having trouble with utf-8 characters in results from sparql-mode. Here's a query that includes the string "cm²" in the result, running e.g. in eshell:

curl "https://endpoint.dexpi.org/information_model/query?query=describe%20<http://sandbox.dexpi.org/informationmodel/ScaleCentimetreSquared>"

Executing the describe from a sparql-mode buffer, I see this -- uninterpretable characters:

"cm\302\262"

I have utf-8 as default character set. Emacs 27.2 on Windows, sparql-mode 4.0.2.

johanwk commented 3 years ago

Here's a small change to sparql-handle-results that seems to fix the issue. I've used (car default-process-coding-system) to hopefully obtain the utf-8 choice in a reasonable way.

(defun sparql-handle-results (status &optional output-buffer)
  "Handles the result that comes back from url-retrieve for a
SPARQL query."
  (when (zerop (buffer-size))
    (setq mode-name "SPARQL[error]")
    (error "URL '%s' is not accessible"
           (url-recreate-url url-current-object)))
  (let ((results-buffer (current-buffer))
        (response (url-http-parse-response)))
    (with-current-buffer output-buffer
      (let ((buffer-read-only nil))
        (if (and (<= 200 response) (<= response 299))
; here: 
            (progn (url-insert results-buffer)
                   (decode-coding-region (point-min) (point-max) (car default-process-coding-system)))
;
          (insert-buffer-substring results-buffer))
        (setq mode-name "SPARQL[finished]")))))