Skip to content

fix: escape and url-encode embark field values; respect user --type=#7

Merged
chiply merged 2 commits into
mainfrom
fix/escape-field-values-in-embark-search
Apr 24, 2026
Merged

fix: escape and url-encode embark field values; respect user --type=#7
chiply merged 2 commits into
mainfrom
fix/escape-field-values-in-embark-search

Conversation

@chiply

@chiply chiply commented Apr 24, 2026

Copy link
Copy Markdown
Owner

Summary

  • Quote album/artist values in the embark "list tracks" actions; make spot--parse-command treat -- inside double quotes as part of the query; URL-encode the q value before it hits the request layer.
  • Stop emitting the broad default type=… list when the user supplied their own --type=, so e.g. "list album tracks" now actually returns only tracks.

Reported externally on Mastodon (@jplindstrom) as a possible escaping bug; second issue surfaced while verifying the first fix in a live session.

Test plan

  • eask compile clean
  • eask test ert test/spot-test.el — 47/47 pass (6 new tests)
  • eask lint package, checkdoc, relint — no new findings
  • Manually verified in a running Emacs daemon: searching tracks for an album now returns tracks only, and an album/artist name containing -- no longer corrupts the query

Charlie Holland added 2 commits April 24, 2026 01:36
Embark "list tracks" actions concatenated raw album/artist names
into the consult input string, so a name containing " -- " collided
with the args separator and corrupted the query. The same path also
sent the query into the URL with no percent-encoding, so quoted
values and other special characters never reached Spotify intact.

Wrap field values in double quotes (matching Spotify's search
syntax), make spot--parse-command treat " -- " inside double quotes
as part of the query, and url-hexify-string the q value before it
hits the request layer.
spot--search-items unconditionally appended the broad
type=album,artist,playlist,track,show,episode,audiobook to the
search URL and then concatenated the user's args after it. When
the user supplied --type=track (e.g. via the embark "list album
tracks" action), Spotify saw two type parameters and honored the
first, so other item kinds still leaked into the results.

Extract the q-params builder, and only emit the default type list
when the parsed args don't contain a type entry.
Copilot AI review requested due to automatic review settings April 24, 2026 05:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens Spotify search query handling by properly quoting Embark-generated field filters, improving command parsing so -- inside quotes isn’t treated as an args separator, and URL-encoding the q parameter before making search requests. It also fixes search type handling so a user-supplied --type= overrides the default multi-type list.

Changes:

  • Add quote-aware args separator detection for spot--parse-command.
  • Introduce spot--build-search-q-params to URL-encode q and only apply default type=… when the user didn’t provide one.
  • Quote album/artist field values in Embark “list tracks” actions to avoid query corruption.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
spot-search.el Adds quote-aware parsing and constructs encoded search query params while respecting user --type=.
spot-embark.el Wraps album/artist values in quotes when generating field-filter searches from Embark actions.
test/spot-test.el Adds ERT coverage for quoted parsing behavior and default/user type behavior in q-param building.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread spot-search.el
Comment on lines 102 to +121
@@ -88,19 +108,26 @@ in the form \"--key=value\"."
pairs "")
"")))

(defun spot--build-search-q-params (parsed-command)
"Build the search URL query parameter string for PARSED-COMMAND.
PARSED-COMMAND is the result of `spot--parse-command'. A default
`type' covering every supported item kind is included unless the
user supplied their own `type' argument."
(let* ((query (car parsed-command))
(args-alist (cadr parsed-command))
(args (spot--transform-alist-to-q-params (cdr parsed-command)))
(default-types
(unless (assoc "type" args-alist)
"&type=album,artist,playlist,track,show,episode,audiobook")))

Copilot AI Apr 24, 2026

Copy link

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-params is documented as taking an alist, but it actually expects a list whose car is the alist (it does (car alist)). The new spot--build-search-q-params reinforces this by passing (cdr parsed-command) even though args-alist is already available, which makes the API easy to misuse and hard to maintain. Consider updating spot--transform-alist-to-q-params to accept the plain args alist (or fix the docstring), and then call it with args-alist here to avoid the extra wrapper structure.

Copilot uses AI. Check for mistakes.
Comment thread test/spot-test.el
Comment on lines +141 to 142


Copilot AI Apr 24, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new spot--build-search-q-params URL-encodes q via url-hexify-string, but the added tests only cover default-type behavior and not the encoding itself. Add a test that uses a query containing spaces/quotes/field syntax (e.g. artist:"Pink Floyd" or album:"Foo -- Live") and asserts the resulting q-params contains the expected percent-encoding (at least %20/%22/%3A), so regressions in escaping are caught.

Suggested change
(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))))

Copilot uses AI. Check for mistakes.
@chiply chiply merged commit b53ab9c into main Apr 24, 2026
11 checks passed
@chiply chiply deleted the fix/escape-field-values-in-embark-search branch April 24, 2026 05:49
@chiply chiply mentioned this pull request Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants