From 9ad22dbf34574c5d6070724eba0d22350b347e6b Mon Sep 17 00:00:00 2001 From: Laurence Warne Date: Sun, 18 Aug 2024 11:03:46 +0100 Subject: [PATCH] Fix invalid json being sent (not escaping " and \n) for reviews --- .github/workflows/test.yml | 2 +- finito-buffer.el | 2 +- finito-graphql.el | 2 +- finito.el | 14 +++++++++----- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b127286..d0eed6f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,7 +29,7 @@ jobs: - name: Set up Emacs uses: purcell/setup-emacs@master with: - version: ${{matrix.emacs_version}} + version: ${{ matrix.emacs_version }} - name: Install Eldev run: curl -fsSL https://raw.github.com/doublep/eldev/master/webinstall/github-eldev | sh diff --git a/finito-buffer.el b/finito-buffer.el index f86c46c..ab96731 100644 --- a/finito-buffer.el +++ b/finito-buffer.el @@ -292,7 +292,7 @@ BOOK-ALIST is an alist of the format returned by `finito--create-book-alist'" nil 'equal)) (bound-and-true-p finito--show-reviews)) - (when review + (when (and review (not (s-blank-p review))) (let ((review-header "Review:")) (insert review-header) (overlay-put (make-overlay (point) (- (point) (length review-header))) diff --git a/finito-graphql.el b/finito-graphql.el index 371f2c0..29898b2 100644 --- a/finito-graphql.el +++ b/finito-graphql.el @@ -201,7 +201,7 @@ (defconst finito--review-book-mutation-variables "{ - \"review\": \"%s\", + \"review\": %s, \"book\": { \"title\": \"%s\", \"authors\": %s, diff --git a/finito.el b/finito.el index 60714d0..672c222 100644 --- a/finito.el +++ b/finito.el @@ -173,6 +173,7 @@ CALLBACK is called with the parsed json if the request is successful. If SYNC is non-nil make the request synchronous. If errors are detected in the graphql response body, then call GRAPHQL-ERROR with the first error as a symbol." + (when finito--debug (message "Finito request content: '%s'" request-plist)) (request (finito--host-uri) :type "POST" :headers (plist-get request-plist :headers) @@ -840,17 +841,20 @@ Note this overwrites any existing review." (coll-buf (current-buffer)) (buf (generate-new-buffer (format "%s Review" (alist-get 'title book))))) (with-current-buffer buf + ;; TODO make a major mode (local-set-key (kbd "C-c C-c") (lambda () (interactive) (finito--make-request (finito--review-book-request-plist book - (buffer-substring-no-properties (point-min) (point-max))) - (lambda (&rest _) (format "Added review for '%s'" (alist-get 'title book)))) - (kill-buffer-and-window) - (with-current-buffer coll-buf - (revert-buffer))))) + (json-encode-string (buffer-substring-no-properties (point-min) (point-max)))) + (lambda (&rest _) + (with-current-buffer coll-buf (revert-buffer)) + (format "Added review for '%s'" (alist-get 'title book)))) + (kill-buffer-and-window))) + (when-let ((review (alist-get 'review book))) + (insert review))) (pop-to-buffer buf '(display-buffer-below-selected . nil)) (message "Use C-c C-c to submit the review"))))