Fix to Emacs hang when viewing ClojureDocs for "/"#3900
Conversation
More general way of removing namespace from symbol, so the symbol can be properly highlighted in the ClojureDocs buffer. Emacs hangs terribly if it tries to highlight "".
|
|
||
| (describe "cider-clojuredocs-lookup-remove-namespace" | ||
| (it "removes namespace from symbol to highlight only the name" | ||
| (expect (replace-regexp-in-string "^.+?/" "" "clojure.core//") :to-equal "/") |
There was a problem hiding this comment.
You're not really testing cider-clojuredocs-lookup-remove-namespace, but only the built-in replace-regexp-in-string with your test.
There was a problem hiding this comment.
Yes, the intention with the test is to show that the regex behaves as intended. Didn't want to break out the replace-regexp-in-string into a new function.
Edit: Saw your comment below now.
|
Nice catch on the bug! The fix works. Two thoughts while we're here: The regex could be tighter and line up with patterns already in the codebase. (replace-regexp-in-string "\\`[^/]+/" "" sym)Same behavior on The other thing: the new tests exercise the regex inline, not the production code — if someone tweaks the regex inside (defun cider-clojuredocs--strip-ns (sym)
"Strip the namespace prefix from SYM, leaving just the symbol name."
(replace-regexp-in-string "\\`[^/]+/" "" sym))And then: (describe "cider-clojuredocs--strip-ns"
(it "removes the namespace from qualified symbols"
(expect (cider-clojuredocs--strip-ns "clojure.core/subs") :to-equal "subs")
(expect (cider-clojuredocs--strip-ns "clojure.string/trim") :to-equal "trim"))
(it "preserves a slash symbol name (the bug being fixed)"
(expect (cider-clojuredocs--strip-ns "clojure.core//") :to-equal "/"))
(it "preserves operator-like names"
(expect (cider-clojuredocs--strip-ns "clojure.core/+") :to-equal "+"))
(it "leaves unqualified symbols unchanged"
(expect (cider-clojuredocs--strip-ns "subs") :to-equal "subs"))) |
|
Clever with the "is" comments in the tests. Thanks. Learning... |
More general way of removing namespace from symbol, so the symbol can be properly highlighted in the ClojureDocs buffer. Emacs hangs terribly if it tries to highlight "". Thanks to @bbatsov for cleverer solution and better tests.
|
PR modified - with an extra test for unqualified "/" added. |
|
Yeah, I can squash when merging. Thanks! |
Emacs hangs terribly with 100% CPU usage and enormous memory consumption if it is forced to highlight "" in a buffer.
Requesting ClojureDocs for / triggers the issue.
This PR prevents it, by correctly removing the namespace - keeping only the symbol name.
eldev test)eldev lint)Steps to reproduce the problem
With cursor after a lone /
Don't do
C-cC-dC-cbecause it will send Emacs on a memory-eating spree and never return.
Occasionally it's possible to interrupt with
C-g, but usually one needs to kill the Emacs process.CIDER version information
cidermaster branchand any version before that, probably since at least 2022
Emacs version
30.2
28.2
Operating system
macOS and Linux