From 81ccd49801921811ffd81240ce8d739f15e4d887 Mon Sep 17 00:00:00 2001 From: ikappaki Date: Sat, 2 Dec 2023 12:09:23 +0000 Subject: [PATCH] pwsh 7.3 quoting rules compatibility Co-authored-by: shishini --- CHANGELOG.md | 4 ++++ cider.el | 5 ++++- .../ROOT/pages/basics/up_and_running.adoc | 19 ++++++++++++++----- test/cider-tests.el | 6 +++--- test/integration/integration-tests.el | 6 +++++- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ce8adfae..f4fbcc50e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## master (unreleased) +### Changes + +- [#3588](https://github.com/clojure-emacs/cider/issues/3588): Compatibility with pwsh 7.3 quoting rules. + ## 1.12.0 (2023-11-24) ### Changes diff --git a/cider.el b/cider.el index 601bc0399..b673bdda7 100644 --- a/cider.el +++ b/cider.el @@ -810,7 +810,10 @@ rules to quote it." (defun cider--powershell-encode-command (cmd-params) "Base64 encode the powershell command and jack-in CMD-PARAMS for clojure-cli." (let* ((quoted-params cmd-params) - (command (format "clojure %s" quoted-params)) + ;; Also ensure compatibility with pwsh 7.3 quoting rules + ;; + ;; https://stackoverflow.com/a/59036879 + (command (format "$PSNativeCommandArgumentPassing = 'Legacy'; clojure %s" quoted-params)) (utf-16le-command (encode-coding-string command 'utf-16le))) (format "-encodedCommand %s" (base64-encode-string utf-16le-command t)))) diff --git a/doc/modules/ROOT/pages/basics/up_and_running.adoc b/doc/modules/ROOT/pages/basics/up_and_running.adoc index f212c8e51..c8e17cc31 100644 --- a/doc/modules/ROOT/pages/basics/up_and_running.adoc +++ b/doc/modules/ROOT/pages/basics/up_and_running.adoc @@ -208,11 +208,20 @@ so we'll examine them tool by tool. * `cider-clojure-cli-parameters` - the command-line parameters to start a REPL * `cider-clojure-cli-aliases` - a list of aliases to be used at jack-in time -To use `cider-jack-in` with `tools.deps` on Windows set the -`cider-clojure-cli-command` to `"powershell"`. This happens by default -if you are on Windows and no `clojure` executable is found. Using -`"powershell"` will Base64 encode the clojure launch command before -passing it to PowerShell and avoids shell-escaping issues. +On MS-Windows, CIDER will employ `PowerShell` to execute Clojure if no +`clojure` executable is found in the PATH (e.g. like the one supplied +by https://github.com/borkdude/deps.clj[deps.clj]). The default +executable used is `powershell` which is available on all Windows +platforms. Using `PowerShell` will Base64 encode the clojure launch +command before passing it to PowerShell and avoids shell-escaping +issues. + +The functionality of `cider-clojure-cli-command` has been verified +with the following alternatives + +* `pwsh`: This option proves beneficial when the user has installed the https://github.com/clojure/tools.deps.alpha/wiki/clj-on-Windows[ClojureTools] module on pwsh in a directory not accessible by the system's PowerShell installation. +* `deps.exe`: This executable is part of the tools provided by + https://github.com/borkdude/deps.clj[deps.clj] as an alternative name for `clojure.exe`. NOTE: Alternatively you can use WSL (e.g. to run nREPL and Emacs there), which will likely result in a better overall development experience. diff --git a/test/cider-tests.el b/test/cider-tests.el index d89db352e..19f8d01b7 100644 --- a/test/cider-tests.el +++ b/test/cider-tests.el @@ -420,12 +420,12 @@ (expect (cider--powershell-encode-command "cmd-params") :to-equal (concat "-encodedCommand " ;; Eval to reproduce reference string below: (base64-encode-string (encode-coding-string "clojure cmd-params" 'utf-16le) t) - "YwBsAG8AagB1AHIAZQAgAGMAbQBkAC0AcABhAHIAYQBtAHMA"))) + "JABQAFMATgBhAHQAaQB2AGUAQwBvAG0AbQBhAG4AZABBAHIAZwB1AG0AZQBuAHQAUABhAHMAcwBpAG4AZwAgAD0AIAAnAEwAZQBnAGEAYwB5ACcAOwAgAGMAbABvAGoAdQByAGUAIABjAG0AZAAtAHAAYQByAGEAbQBzAA=="))) (it "escapes double quotes by repeating them" (expect (cider--powershell-encode-command "\"cmd-params\"") :to-equal (concat "-encodedCommand " ;; Eval to reproduce reference string below: (base64-encode-string (encode-coding-string "clojure "\"cmd-params\""" 'utf-16le) t) - "YwBsAG8AagB1AHIAZQAgACIAYwBtAGQALQBwAGEAcgBhAG0AcwAiAA==")))) + "JABQAFMATgBhAHQAaQB2AGUAQwBvAG0AbQBhAG4AZABBAHIAZwB1AG0AZQBuAHQAUABhAHMAcwBpAG4AZwAgAD0AIAAnAEwAZQBnAGEAYwB5ACcAOwAgAGMAbABvAGoAdQByAGUAIAAiAGMAbQBkAC0AcABhAHIAYQBtAHMAIgA=")))) (describe "cider--update-jack-in-cmd" (describe "when 'clojure-cli project type and \"powershell\" command" @@ -441,7 +441,7 @@ (expect (plist-get (cider--update-jack-in-cmd nil) :jack-in-cmd) :to-equal (concat "resolved-powershell -encodedCommand " ;; Eval to reproduce reference string below: (base64-encode-string (encode-coding-string "clojure "\"cmd-params"\"" 'utf-16le) t) - "YwBsAG8AagB1AHIAZQAgACIAYwBtAGQALQBwAGEAcgBhAG0AcwAiAA==")))) + "JABQAFMATgBhAHQAaQB2AGUAQwBvAG0AbQBhAG4AZABBAHIAZwB1AG0AZQBuAHQAUABhAHMAcwBpAG4AZwAgAD0AIAAnAEwAZQBnAGEAYwB5ACcAOwAgAGMAbABvAGoAdQByAGUAIAAiAGMAbQBkAC0AcABhAHIAYQBtAHMAIgA=")))) (describe "when 'clojure-cli project type" (it "uses main opts in an alias to prevent other mains from winning" (setq-local cider-jack-in-dependencies nil) diff --git a/test/integration/integration-tests.el b/test/integration/integration-tests.el index a337e63fb..c4ddf8cba 100644 --- a/test/integration/integration-tests.el +++ b/test/integration/integration-tests.el @@ -187,7 +187,11 @@ If CLI-COMMAND is nil, then use the default." (jack-in-clojure-cli-test nil)) (when (eq system-type 'windows-nt) - (it "to clojure tools cli (alternative deps.exe)" + (it "to clojure tools cli (alternative pwsh)" + (jack-in-clojure-cli-test "pwsh"))) + +(when (eq system-type 'windows-nt) + (it "to clojure tools cli (alternative deps.exe)" (jack-in-clojure-cli-test "deps.exe"))) (it "to leiningen"