-
Notifications
You must be signed in to change notification settings - Fork 0
fix: escape and url-encode embark field values; respect user --type= #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -94,6 +94,51 @@ | |||||||||||||||||||||
| (should (equal (car result) "jazz")) | ||||||||||||||||||||||
| (should (= (length (cadr result)) 2)))) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| (ert-deftest spot-test-parse-command/quoted-field-with-separator () | ||||||||||||||||||||||
| "A \" -- \" inside a double-quoted field is part of the query." | ||||||||||||||||||||||
| (let ((result (spot--parse-command | ||||||||||||||||||||||
| "album:\"Foo -- Live\" artist:\"Bar\" -- --type=track"))) | ||||||||||||||||||||||
| (should (equal (car result) "album:\"Foo -- Live\" artist:\"Bar\"")) | ||||||||||||||||||||||
| (should (equal (cadr result) '(("type" . "track")))))) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| (ert-deftest spot-test-parse-command/quoted-field-no-args () | ||||||||||||||||||||||
| "A quoted field with an internal \" -- \" but no real args separator." | ||||||||||||||||||||||
| (let ((result (spot--parse-command "album:\"Foo -- Live\""))) | ||||||||||||||||||||||
| (should (equal (car result) "album:\"Foo -- Live\"")) | ||||||||||||||||||||||
| (should-not (cadr result)))) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| (ert-deftest spot-test-parse-command/quoted-field-with-spaces () | ||||||||||||||||||||||
| "Spaces inside a quoted field are preserved in the query." | ||||||||||||||||||||||
| (let ((result (spot--parse-command | ||||||||||||||||||||||
| "artist:\"Pink Floyd\" -- --type=track"))) | ||||||||||||||||||||||
| (should (equal (car result) "artist:\"Pink Floyd\"")) | ||||||||||||||||||||||
| (should (equal (cadr result) '(("type" . "track")))))) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ;;; spot--build-search-q-params | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| (ert-deftest spot-test-build-search-q-params/default-types-when-no-args () | ||||||||||||||||||||||
| "The default type list is included when no args are given." | ||||||||||||||||||||||
| (let ((q (spot--build-search-q-params '("radiohead" nil)))) | ||||||||||||||||||||||
| (should (string-match-p "q=radiohead" q)) | ||||||||||||||||||||||
| (should (string-match-p | ||||||||||||||||||||||
| "&type=album,artist,playlist,track,show,episode,audiobook" | ||||||||||||||||||||||
| q)))) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| (ert-deftest spot-test-build-search-q-params/user-type-replaces-default () | ||||||||||||||||||||||
| "A user-supplied type arg replaces the default type list." | ||||||||||||||||||||||
| (let ((q (spot--build-search-q-params | ||||||||||||||||||||||
| '("foo" (("type" . "track")))))) | ||||||||||||||||||||||
| (should-not (string-match-p "type=album," q)) | ||||||||||||||||||||||
| (should (string-match-p "&type=track" q)))) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| (ert-deftest spot-test-build-search-q-params/non-type-args-keep-default () | ||||||||||||||||||||||
| "Non-type args don't suppress the default type list." | ||||||||||||||||||||||
| (let ((q (spot--build-search-q-params | ||||||||||||||||||||||
| '("foo" (("market" . "US")))))) | ||||||||||||||||||||||
| (should (string-match-p "&type=album," q)) | ||||||||||||||||||||||
| (should (string-match-p "&market=US" q)))) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
Comment on lines
+141
to
142
|
||||||||||||||||||||||
| (ert-deftest spot-test-build-search-q-params/url-encodes-query () | |
| "The q param is percent-encoded for spaces, quotes, and field syntax." | |
| (let ((q (spot--build-search-q-params | |
| '("artist:\"Pink Floyd\"" nil)))) | |
| (should (string-match-p "q=artist%3A%22Pink%20Floyd%22" q)) | |
| (should (string-match-p "%3A" q)) | |
| (should (string-match-p "%22" q)) | |
| (should (string-match-p "%20" q)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spot--transform-alist-to-q-paramsis documented as taking an alist, but it actually expects a list whose car is the alist (it does(car alist)). The newspot--build-search-q-paramsreinforces this by passing(cdr parsed-command)even thoughargs-alistis already available, which makes the API easy to misuse and hard to maintain. Consider updatingspot--transform-alist-to-q-paramsto accept the plain args alist (or fix the docstring), and then call it withargs-alisthere to avoid the extra wrapper structure.