From 46ffa2e964aa120e4cab777f315bd9058f97b097 Mon Sep 17 00:00:00 2001 From: Ruijie Yu Date: Tue, 4 Apr 2023 17:54:01 +0800 Subject: [PATCH] Protect against symbols with unsafe chars Fixes #648. * lispy.el lispy--symbol-safe-chars-regexp: define safe chars. (lispy--read): protect against unsafe chars in a symbol. --- lispy.el | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lispy.el b/lispy.el index 0c5c9720..b153a6b7 100644 --- a/lispy.el +++ b/lispy.el @@ -7286,6 +7286,12 @@ See https://clojure.org/guides/weird_characters#_character_literal.") (match-string subexp))) t t nil subexp))))) +(defconst lispy--symbol-safe-chars-regexp + (rx (any alnum ?+ ?- ?* ?/ ?: ?=)) + "Regexp for \"safe\" characters. +Safe characters are those which are suitable for a symbol and +have no special reader syntax.") + ;; TODO: Make the read test pass on string with semi-colon (defun lispy--read (str) "Read STR including comments and newlines." @@ -7524,11 +7530,13 @@ See https://clojure.org/guides/weird_characters#_character_literal.") (unless (lispy--in-string-or-comment-p) (replace-match (format "(ly-raw racket-option %s)" (match-string 1))))) - ;; Clojure # in a symbol + ;; Protect symbols containing unsafe characters (goto-char (point-min)) (while (re-search-forward "\\_<\\(?:\\sw\\|\\s_\\)+\\_>" nil t) (unless (lispy--in-string-p) - (when (cl-position ?# (match-string 0)) + (when (not (string-match + lispy--symbol-safe-chars-regexp + (match-string 0))) (let* ((bnd (lispy--bounds-dwim)) (str (lispy--string-dwim bnd))) (delete-region (car bnd) (cdr bnd))