Git Product home page Git Product logo

Comments (27)

tarsius avatar tarsius commented on July 17, 2024 1

‘test’

from ghub.

vermiculus avatar vermiculus commented on July 17, 2024 1

I…I don't know what's real anymore.

Turns out that (multibyte-string-p (symbol-name 'post)) is true. The real culprit here is not data at all – it's the method that's being converted from a symbol to a string in ghubp-request.

😱

from ghub.

tarsius avatar tarsius commented on July 17, 2024 1

I have added a safety net to ghub too.

That doesn't really explain the discrepancy (375+23 being both 404 and 398),

I think I know why that is so, see the commit message.

from ghub.

vermiculus avatar vermiculus commented on July 17, 2024

For example, note the multibyte characters and in the body element of the following payload:

Contacting host: api.github.com:443
url-http-create-request: Multibyte text in HTTP request: POST /repos/vermiculus/magithub/issues/166/comments HTTP/1.1
MIME-Version: 1.0
Connection: keep-alive
Extension: Security/Digest Security/SSL
Host: api.github.com
Accept-encoding: gzip
Accept: */*
User-Agent: URL/Emacs
Cookie: HttpOnly=nil; logged_in=no
Content-Type: application/json
Authorization: token --snip--
Content-length: 1185

{"body":"in\n‘~/dotfiles/.emacs.d/elpa/magit-20171116.427/magit-log.el’.\n"}

from ghub.

vermiculus avatar vermiculus commented on July 17, 2024

Related to #10 and #12.

from ghub.

tarsius avatar tarsius commented on July 17, 2024

test

from ghub.

tarsius avatar tarsius commented on July 17, 2024

This was created with

(ghub-post "/repos/magit/ghub/issues/35/comments" nil '((body . "‘test’")))

and latest commit on next. I didn't change anything. Does this not work for you?

from ghub.

vermiculus avatar vermiculus commented on July 17, 2024

Hm, I've been working on master; I'll try next tonight after work.

Although it is odd -- nothing unique to next seems relevant.

from ghub.

vermiculus avatar vermiculus commented on July 17, 2024

Even stranger – I'm still getting the error on next in a fresh emacs and emacs -Q:

Debugger entered--Lisp error: (error "Multibyte text in HTTP request: POST /repos/magit/ghub/issues/35/comments HTTP/1.1
MIME-Version: 1.0
Connection: keep-alive
Extension: Security/Digest Security/SSL
Host: api.github.com
Accept-encoding: gzip
Accept: */*
User-Agent: URL/Emacs
Cookie: HttpOnly=nil; logged_in=no
Content-Type: application/json
Authorization: token [redacted]
Content-length: 17

{\"body\":\"‘test’\"}")
  signal(error ("Multibyte text in HTTP request: POST /repos/magit/ghub/issues/35/comments HTTP/1.1
\nMIME-Version: 1.0
\nConnection: keep-alive
\nExtension: Security/Digest Security/SSL
\nHost: api.github.com
\nAccept-encoding: gzip
\nAccept: */*
\nUser-Agent: URL/Emacs
\nCookie: HttpOnly=nil; logged_in=no
\nContent-Type: application/json
\nAuthorization: token [redacted]
\nContent-length: 17
\n
\n{\"body\":\"‘test’\"}"))
  error("Multibyte text in HTTP request: %s" "POST /repos/magit/ghub/issues/35/comments HTTP/1.1
\nMIME-Version: 1.0
\nConnection: keep-alive
\nExtension: Security/Digest Security/SSL
\nHost: api.github.com
\nAccept-encoding: gzip
\nAccept: */*
\nUser-Agent: URL/Emacs
\nCookie: HttpOnly=nil; logged_in=no
\nContent-Type: application/json
\nAuthorization: token [redacted]
\nContent-length: 17
\n
\n{\"body\":\"‘test’\"}")
  url-http-create-request()
  url-http([cl-struct-url "https" nil nil "api.github.com" nil "/repos/magit/ghub/issues/35/comments" nil nil t nil t] #[128 "\302\303\304p#\210\300\305\240\210\301p\240\207" [(nil) (nil) url-debug retrieval "Synchronous fetching done (%S)" t] 5 "\n\n(fn &rest IGNORED)"] (nil) nil tls)
  url-https([cl-struct-url "https" nil nil "api.github.com" nil "/repos/magit/ghub/issues/35/comments" nil nil t nil t] #[128 "\302\303\304p#\210\300\305\240\210\301p\240\207" [(nil) (nil) url-debug retrieval "Synchronous fetching done (%S)" t] 5 "\n\n(fn &rest IGNORED)"] (nil))
  url-retrieve-internal("https://api.github.com/repos/magit/ghub/issues/35/comments" #[128 "\302\303\304p#\210\300\305\240\210\301p\240\207" [(nil) (nil) url-debug retrieval "Synchronous fetching done (%S)" t] 5 "\n\n(fn &rest IGNORED)"] (nil) nil nil)
  url-retrieve("https://api.github.com/repos/magit/ghub/issues/35/comments" #[128 "\302\303\304p#\210\300\305\240\210\301p\240\207" [(nil) (nil) url-debug retrieval "Synchronous fetching done (%S)" t] 5 "\n\n(fn &rest IGNORED)"] nil nil nil)
  url-retrieve-synchronously("https://api.github.com/repos/magit/ghub/issues/35/comments")
  (set-buffer (url-retrieve-synchronously (concat ghub-base-url resource p)))
  (save-current-buffer (set-buffer (url-retrieve-synchronously (concat ghub-base-url resource p))) (let (link body) (goto-char (point-min)) (save-restriction (narrow-to-region (point) url-http-end-of-headers) (and (setq link (mail-fetch-field "Link")) (setq link (car (rassoc (list "rel=\"next\"") (mapcar ... ...)))) (string-match "[?&]page=\\([^&>]+\\)" link) (setq link (match-string 1 link)))) (goto-char (1+ url-http-end-of-headers)) (setq body (ghub--read-response)) (if (or noerror (= (/ url-http-response-status 100) 2)) nil (cond ((eq url-http-response-status 301) (let nil (signal (quote ghub-301) (list method resource p d body)))) ((eq url-http-response-status 400) (let nil (signal (quote ghub-400) (list method resource p d body)))) ((eq url-http-response-status 404) (let nil (signal (quote ghub-404) (list method resource p d body)))) ((eq url-http-response-status 422) (let nil (signal (quote ghub-422) (list method resource p d body)))) (t (let nil (signal (quote ghub-http-error) (list url-http-response-status method resource p d body)))))) (if (and link ghub-unpaginate) (nconc body (ghub--request method resource (cons (cons (quote page) link) (cl-delete (quote page) params :key (function car))) data noerror)) body)))
  (let* ((p (and params (concat "?" (ghub--url-encode-params params)))) (d (and data (json-encode-list data))) (url-request-extra-headers (cons (quote ("Content-Type" . "application/json")) (let* ((token (and t ...))) (if token (list (cons "Authorization" ...)))))) (url-request-method method) (url-request-data d)) (save-current-buffer (set-buffer (url-retrieve-synchronously (concat ghub-base-url resource p))) (let (link body) (goto-char (point-min)) (save-restriction (narrow-to-region (point) url-http-end-of-headers) (and (setq link (mail-fetch-field "Link")) (setq link (car (rassoc ... ...))) (string-match "[?&]page=\\([^&>]+\\)" link) (setq link (match-string 1 link)))) (goto-char (1+ url-http-end-of-headers)) (setq body (ghub--read-response)) (if (or noerror (= (/ url-http-response-status 100) 2)) nil (cond ((eq url-http-response-status 301) (let nil (signal ... ...))) ((eq url-http-response-status 400) (let nil (signal ... ...))) ((eq url-http-response-status 404) (let nil (signal ... ...))) ((eq url-http-response-status 422) (let nil (signal ... ...))) (t (let nil (signal ... ...))))) (if (and link ghub-unpaginate) (nconc body (ghub--request method resource (cons (cons ... link) (cl-delete ... params :key ...)) data noerror)) body))))
  ghub--request("POST" "/repos/magit/ghub/issues/35/comments" nil ((body . "‘test’")) nil)
  ghub-post("/repos/magit/ghub/issues/35/comments" nil ((body . "‘test’")))
  eval((ghub-post "/repos/magit/ghub/issues/35/comments" nil (quote ((body . "‘test’")))) nil)
  elisp--eval-last-sexp(nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  call-interactively(eval-last-sexp nil nil)
  command-execute(eval-last-sexp)

from ghub.

tarsius avatar tarsius commented on July 17, 2024

What does

(multibyte-string-p "`")

return for you?

from ghub.

tarsius avatar tarsius commented on July 17, 2024

What Emacs version are you using?

https://debbugs.gnu.org/cgi/bugreport.cgi?bug=24117 seems to be related, but is about the url not the payload.

from ghub.

tarsius avatar tarsius commented on July 17, 2024

I intentionally triggered an error as where it occurs for you and I got

{"body":"\342\200\230test\232\200\231"}

Try

diff --git a/ghub.el b/ghub.el
index 350e87a..6ef8fa0 100644
--- a/ghub.el
+++ b/ghub.el
@@ -144,7 +144,7 @@ (cl-defun ghub-request (method resource &optional params
       (error "PARAMS and PAYLOAD are mutually exclusive for METHOD %S" method))
     (setq payload params)))
   (when (and payload (not (stringp payload)))
-    (setq payload (encode-coding-string (json-encode-list payload) 'utf-8)))
+    (setq payload (encode-coding-string (json-encode-list payload) 'us-ascii)))
   (let* ((qry (and query (concat "?" (ghub--url-encode-params query))))
          (buf (let ((url-request-extra-headers
                      `(("Content-Type" . "application/json")

from ghub.

tarsius avatar tarsius commented on July 17, 2024

I'm still getting the error

Did you run (ghub-post "/repos/magit/ghub/issues/35/comments" '((body . "‘test’"))) or did you use magithub? In case its the latter, try making the buffer unibyte using (set-buffer-multibyte nil) before inserting any text.

from ghub.

vermiculus avatar vermiculus commented on July 17, 2024

I ran the former, but I'll still try set-buffer-multibyte when I can. Unfortunately High Sierra highly tanked my laptop; I've got an appointment to get it fixed later this evening, but there are no guarantees 😢

from ghub.

tarsius avatar tarsius commented on July 17, 2024

‘test’

from ghub.

tarsius avatar tarsius commented on July 17, 2024

‘test’

from ghub.

vermiculus avatar vermiculus commented on July 17, 2024

‘test’

from ghub.

vermiculus avatar vermiculus commented on July 17, 2024

‘test’

from ghub.

vermiculus avatar vermiculus commented on July 17, 2024

Alright, works from a fresh emacs with no real fiddling. I'm not sure what changed, but I'll close this issue.

Thanks for your help!

from ghub.

tarsius avatar tarsius commented on July 17, 2024

Looks like I can only reproduce #35 if I'm doing it from a Magithub workflow; I suspect there is indeed something wrong with the buffer's multibyte settings, but no valid input of set-buffer-multibyte is having any effect 
You can reproduce by pressing r on an issue section or in an issue buffer from Magithub and trying to submit a multibyte comment

I can reproduce that but it doesn't seem to have anything to do with the text being read from a buffer. If I edit magithub-issue-comment-submit to use a hard-coded string instead, then the same happens.

from ghub.

vermiculus avatar vermiculus commented on July 17, 2024

I can also reproduce with the following:

 (ghubp-post-repos-owner-repo-issues-number-comments
  '((owner (login . "vermiculus"))
    (name . "my-new-repository"))
  '((number . 39))
  '((body . "–test–"))) ;; multibyte text here

but not with

(ghub-post "/repos/vermiculus/my-new-repository/issues/39/comments" '((body . "–test–")))

Something's funky.

from ghub.

tarsius avatar tarsius commented on July 17, 2024

Even though the payload seems to trigger the issue, this is actually true (= (string-bytes payload) (length payload)) and (multibyte-string-p payload) is nil.

from ghub.

vermiculus avatar vermiculus commented on July 17, 2024

It's not true when I evaluate the ghub+ form.

from ghub.

vermiculus avatar vermiculus commented on July 17, 2024

It works if I alter url-http-create-request to pass request through string-as-unibyte before returning it.

Edit: Oddly, this same function is ineffective when pulled up to the ghub+ level:

(magithub-request
 (ghubp-post-repos-owner-repo-issues-number-comments
  '((owner (login . "vermiculus"))
    (name . "my-new-repository"))
  '((number . 39))
  `((body . ,(string-as-unibyte "–test–")))))

from ghub.

tarsius avatar tarsius commented on July 17, 2024
diff --git a/lisp/url/url-http.el b/lisp/url/url-http.el
index 51f158e5c2..21753b806a 100644
--- a/lisp/url/url-http.el
+++ b/lisp/url/url-http.el
@@ -390,7 +390,22 @@ url-http-create-request
              ;; End request
              "\r\n"
              ;; Any data
-             url-http-data))
+             ;;url-http-data
+             ))
+    (message ">>> request %s (%s %s)"
+             (multibyte-string-p request)
+             (string-bytes request)
+             (length request))
+    (message ">>> url-http-data %s (%s %s)"
+             (multibyte-string-p url-http-data)
+             (string-bytes url-http-data)
+             (length url-http-data))
+    (setq request (concat request url-http-data))
+    (message ">>> (concat request url-http-data) %s (%s %s)"
+             (multibyte-string-p request)
+             (string-bytes request)
+             (length request))
+    (user-error "Abort")
     ;; Bug#23750
     (unless (= (string-bytes request)
                (length request))
>>> request t (375 375)
>>> url-http-data nil (23 23)
>>> (concat request url-http-data) t (404 398)

I wasn't able to figure out what part inside the (setq request (concat ...)) triggers this. Maybe you have more luck. Commenting/Uncommenting parts changes whether request is multibyte, but seemingly randomly.

from ghub.

vermiculus avatar vermiculus commented on July 17, 2024

Passing method through (encode-coding-string method 'utf-8) resolves the issue. Is this something that should be included in Ghub? Rather, is it possible for Lisp to be read as not utf-8?

from ghub.

vermiculus avatar vermiculus commented on July 17, 2024

That doesn't really explain the discrepancy (375+23 being both 404 and 398), but I'm no expert in coding systems. It does explain why request was multibyte.

Thanks for all your help with this 😄

from ghub.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.