Skip to content
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

Prevent backspace parsing in replace-match #385

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mosquito-magnet
Copy link

Only literal replacement is intended in helm-ag--abbreviate-file-name call to replace-match, so prevent backspace parsing by by passing LITERAL as true.

E.g. if rg is used as helm-ag-base-command, it can output backslashes in its search results for binary files, so an error or unintended replacing behavior could occur.

Reproduction:
(setq helm-ag-base-command "rg --smart-case --no-heading --color=never --line-number --max-columns=150")

I opened git-gutter.el and git-gutter.elc, then used helm-do-ag-buffers to search for "git-gutter:linum-get-overlay" (mostly by accident), and the following error popped up (sorry for overlong backtrace):

Debugger entered--Lisp error: (error "Invalid use of ‘\’ in replacement text")
replace-match("Binary file /home/standard/.emacs.d/elpa/27.1/develop/git-gutter-20211002.2345/git-gutter.elc matches (found "\u{0}" byte around offset 5)\n/mnt/c/Dev/github/git-gutter/git-gutter.el")
helm-ag--abbreviate-file-name()
helm-ag--do-ag-propertize("git-gutter:linum-get-overlay")
#f(compiled-function (process event) #<bytecode 0x1969a2d>)(# "finished\n")
read-from-minibuffer(#("pattern: " 0 9 (face helm-minibuffer-prompt)) "git-gutter:linum-get-overlay" (keymap (M-return keymap (104 . helm-minibuffer-history) (105 . helm-minibuffer-history) (97 . helm-toggle-all-marks) (98 "bookmarks" keymap (109 . helm-ff-bookmark-set) (98 . bookmark-jump))) (100663328 . helm-toggle-all-marks) (C-i . undo-tree-redo) (C-end . helm-end-of-buffer) (C-home . helm-beginning-of-buffer) (end) (home) (33554457 . helm-copy-to-buffer) (25 . helm-kill-selection-and-quit) (4 . helm-buffer-run-kill-persistent) (C-iso-lefttab . helm-follow-action-backward) (26 . helm-select-action) (tab . helm-execute-persistent-action) (33554440 . describe-key) (33554443 . helm-follow-action-backward) (33554442 . helm-follow-action-forward) (17 . ace-jump-helm-line) (f13 lambda nil (interactive) (helm-select-nth-action 12)) (f12 lambda nil (interactive) (helm-select-nth-action 11)) (f11 lambda nil (interactive) (helm-select-nth-action 10)) (f10 lambda nil (interactive) (helm-select-nth-action 9)) (f9 lambda nil (interactive) (helm-select-nth-action 8)) (f8 lambda nil (interactive) (helm-select-nth-action 7)) (f7 lambda nil (interactive) (helm-select-nth-action 6)) (f6 lambda nil (interactive) (helm-select-nth-action 5)) (f5 lambda nil (interactive) (helm-select-nth-action 4)) (f4 lambda nil (interactive) (helm-select-nth-action 3)) (f3 lambda nil (interactive) (helm-select-nth-action 2)) (f2 lambda nil (interactive) (helm-select-nth-action 1)) (menu-bar keymap (help-menu keymap (describe keymap (describe-mode . helm-help)))) (help keymap (109 . helm-help)) (23 . backward-kill-word) (f1 lambda nil (interactive) (helm-select-nth-action 0)) (8 . helm-next-source) (20 . helm-toggle-resplit-and-swap-windows) (C-tab . helm-yank-selection) (67108897 . helm-toggle-suspend-update) (3 keymap (57 . helm-execute-selection-action-at-nth-+9) (56 . helm-execute-selection-action-at-nth-+8) (55 . helm-execute-selection-action-at-nth-+7) (54 . helm-execute-selection-action-at-nth-+6) (53 . helm-execute-selection-action-at-nth-+5) (52 . helm-execute-selection-action-at-nth-+4) (51 . helm-execute-selection-action-at-nth-+3) (50 . helm-execute-selection-action-at-nth-+2) (49 . helm-execute-selection-action-at-nth-+1) (63 . helm-help) (110 . #f(compiled-function () (interactive nil) #<bytecode 0x166c101>)) (108 . helm-display-line-numbers-mode) (62 . helm-toggle-truncate-line) (21 . helm-refresh) (6 . helm-follow-mode) (9 . helm-insert-or-copy) (11 . helm-kill-selection-and-quit) (25 . helm-yank-selection) (37 . helm-exchange-minibuffer-and-header-line) (95 . helm-toggle-full-frame) (45 . helm-swap-windows)) (67108987 . helm-enlarge-window) (67108989 . helm-narrow-window) (19 . undefined) (24 keymap (57 . helm-execute-selection-action-at-nth-+9) (56 . helm-execute-selection-action-at-nth-+8) (55 . helm-execute-selection-action-at-nth-+7) (54 . helm-execute-selection-action-at-nth-+6) (53 . helm-execute-selection-action-at-nth-+5) (52 . helm-execute-selection-action-at-nth-+4) (51 . helm-execute-selection-action-at-nth-+3) (50 . helm-execute-selection-action-at-nth-+2) (49 . helm-execute-selection-action-at-nth-+1) (2 . helm-resume-list-buffers-after-quit) (98 . helm-resume-previous-session-after-quit) (6 . helm-quit-and-find-file)) (11 . helm-previous-line) (67108896 . helm-toggle-visible-mark-forward) (0 . helm-toggle-visible-mark) (C-M-up . helm-scroll-other-window-down) (C-M-down . helm-scroll-other-window) (M-prior . helm-scroll-other-window-down) (M-next . helm-scroll-other-window) ...) nil helm-ag--helm-history #("git-gutter:linum-get-overlay" 0 28 (fontified t)) t)
helm-read-from-minibuffer(nil "git-gutter:linum-get-overlay" nil nil (keymap (C-p . helm-ag--previous-file) (C-n . helm-ag--next-file) (left) (right) (M-return keymap (115 . helm-ag--run-save-buffer) (101 . helm-ag-edit)) (3 keymap (63 . helm-ag--do-ag-help)) (12 . helm-ag--do-ag-up-one-level) keymap (normal-state keymap "Auxiliary keymap for Normal stat..." (83 keymap (80 keymap ...))) (left . helm-ag--previous-file) (right . helm-ag--next-file) (24 keymap (19 . helm-ag--run-save-buffer)) (12 . helm-ag--up-one-level) (3 keymap (60 . helm-ag--previous-file) (62 . helm-ag--next-file) (63 . helm-ag-help) (5 . helm-ag-edit) (111 . helm-ag--run-other-window-action)) keymap (M-return keymap (104 . helm-minibuffer-history) (105 . helm-minibuffer-history) (97 . helm-toggle-all-marks) (98 "bookmarks" keymap (109 . helm-ff-bookmark-set) (98 . bookmark-jump))) (100663328 . helm-toggle-all-marks) (C-i . undo-tree-redo) (C-end . helm-end-of-buffer) (C-home . helm-beginning-of-buffer) (end) (home) (33554457 . helm-copy-to-buffer) (25 . helm-kill-selection-and-quit) (4 . helm-buffer-run-kill-persistent) (C-iso-lefttab . helm-follow-action-backward) (26 . helm-select-action) (tab . helm-execute-persistent-action) (33554440 . describe-key) (33554443 . helm-follow-action-backward) (33554442 . helm-follow-action-forward) ...) nil helm-ag--helm-history)
helm-internal(helm-source-do-ag "git-gutter:linum-get-overlay" nil nil nil "helm-ag" (keymap (C-p . helm-ag--previous-file) (C-n . helm-ag--next-file) (left) (right) (M-return keymap (115 . helm-ag--run-save-buffer) (101 . helm-ag-edit)) (3 keymap (63 . helm-ag--do-ag-help)) (12 . helm-ag--do-ag-up-one-level) keymap (normal-state keymap "Auxiliary keymap for Normal stat..." (83 keymap (80 keymap ...))) (left . helm-ag--previous-file) (right . helm-ag--next-file) (24 keymap (19 . helm-ag--run-save-buffer)) (12 . helm-ag--up-one-level) (3 keymap (60 . helm-ag--previous-file) (62 . helm-ag--next-file) (63 . helm-ag-help) (5 . helm-ag-edit) (111 . helm-ag--run-other-window-action)) keymap (M-return keymap (104 . helm-minibuffer-history) (105 . helm-minibuffer-history) (97 . helm-toggle-all-marks) (98 "bookmarks" keymap (109 . helm-ff-bookmark-set) (98 . bookmark-jump))) (100663328 . helm-toggle-all-marks) (C-i . undo-tree-redo) (C-end . helm-end-of-buffer) (C-home . helm-beginning-of-buffer) (end) (home) (33554457 . helm-copy-to-buffer) (25 . helm-kill-selection-and-quit) (4 . helm-buffer-run-kill-persistent) (C-iso-lefttab . helm-follow-action-backward) (26 . helm-select-action) (tab . helm-execute-persistent-action) (33554440 . describe-key) (33554443 . helm-follow-action-backward) (33554442 . helm-follow-action-forward) ...) nil helm-ag--helm-history)
apply(helm-internal (helm-source-do-ag "git-gutter:linum-get-overlay" nil nil nil "helm-ag" (keymap (C-p . helm-ag--previous-file) (C-n . helm-ag--next-file) (left) (right) (M-return keymap (115 . helm-ag--run-save-buffer) (101 . helm-ag-edit)) (3 keymap (63 . helm-ag--do-ag-help)) (12 . helm-ag--do-ag-up-one-level) keymap (normal-state keymap "Auxiliary keymap for Normal state" (83 keymap (80 keymap (67 keymap ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...)))) (left . helm-ag--previous-file) (right . helm-ag--next-file) (24 keymap (19 . helm-ag--run-save-buffer)) (12 . helm-ag--up-one-level) (3 keymap (60 . helm-ag--previous-file) (62 . helm-ag--next-file) (63 . helm-ag-help) (5 . helm-ag-edit) (111 . helm-ag--run-other-window-action)) keymap (M-return keymap (104 . helm-minibuffer-history) (105 . helm-minibuffer-history) (97 . helm-toggle-all-marks) (98 "bookmarks" keymap (109 . helm-ff-bookmark-set) (98 . bookmark-jump))) (100663328 . helm-toggle-all-marks) (C-i . undo-tree-redo) (C-end . helm-end-of-buffer) (C-home . helm-beginning-of-buffer) (end) (home) (33554457 . helm-copy-to-buffer) (25 . helm-kill-selection-and-quit) (4 . helm-buffer-run-kill-persistent) (C-iso-lefttab . helm-follow-action-backward) (26 . helm-select-action) (tab . helm-execute-persistent-action) (33554440 . describe-key) (33554443 . helm-follow-action-backward) (33554442 . helm-follow-action-forward) (17 . ace-jump-helm-line) (f13 lambda nil (interactive) (helm-select-nth-action 12)) (f12 lambda nil (interactive) (helm-select-nth-action 11)) (f11 lambda nil (interactive) (helm-select-nth-action 10)) (f10 lambda nil (interactive) (helm-select-nth-action 9)) (f9 lambda nil (interactive) (helm-select-nth-action 8)) (f8 lambda nil (interactive) (helm-select-nth-action 7)) (f7 lambda nil (interactive) (helm-select-nth-action 6)) (f6 lambda nil (interactive) (helm-select-nth-action 5)) (f5 lambda nil (interactive) (helm-select-nth-action 4)) (f4 lambda nil (interactive) (helm-select-nth-action 3)) (f3 lambda nil (interactive) (helm-select-nth-action 2)) ...) nil helm-ag--helm-history))
helm(helm-source-do-ag "git-gutter:linum-get-overlay" nil nil nil "helm-ag" (keymap (C-p . helm-ag--previous-file) (C-n . helm-ag--next-file) (left) (right) (M-return keymap (115 . helm-ag--run-save-buffer) (101 . helm-ag-edit)) (3 keymap (63 . helm-ag--do-ag-help)) (12 . helm-ag--do-ag-up-one-level) keymap (normal-state keymap "Auxiliary keymap for Normal stat..." (83 keymap (80 keymap ...))) (left . helm-ag--previous-file) (right . helm-ag--next-file) (24 keymap (19 . helm-ag--run-save-buffer)) (12 . helm-ag--up-one-level) (3 keymap (60 . helm-ag--previous-file) (62 . helm-ag--next-file) (63 . helm-ag-help) (5 . helm-ag-edit) (111 . helm-ag--run-other-window-action)) keymap (M-return keymap (104 . helm-minibuffer-history) (105 . helm-minibuffer-history) (97 . helm-toggle-all-marks) (98 "bookmarks" keymap (109 . helm-ff-bookmark-set) (98 . bookmark-jump))) (100663328 . helm-toggle-all-marks) (C-i . undo-tree-redo) (C-end . helm-end-of-buffer) (C-home . helm-beginning-of-buffer) (end) (home) (33554457 . helm-copy-to-buffer) (25 . helm-kill-selection-and-quit) (4 . helm-buffer-run-kill-persistent) (C-iso-lefttab . helm-follow-action-backward) (26 . helm-select-action) (tab . helm-execute-persistent-action) (33554440 . describe-key) (33554443 . helm-follow-action-backward) (33554442 . helm-follow-action-forward) ...) nil helm-ag--helm-history)
apply(helm (helm-source-do-ag "git-gutter:linum-get-overlay" nil nil nil "helm-ag" (keymap (C-p . helm-ag--previous-file) (C-n . helm-ag--next-file) (left) (right) (M-return keymap (115 . helm-ag--run-save-buffer) (101 . helm-ag-edit)) (3 keymap (63 . helm-ag--do-ag-help)) (12 . helm-ag--do-ag-up-one-level) keymap (normal-state keymap "Auxiliary keymap for Normal state" (83 keymap (80 keymap (67 keymap ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...)))) (left . helm-ag--previous-file) (right . helm-ag--next-file) (24 keymap (19 . helm-ag--run-save-buffer)) (12 . helm-ag--up-one-level) (3 keymap (60 . helm-ag--previous-file) (62 . helm-ag--next-file) (63 . helm-ag-help) (5 . helm-ag-edit) (111 . helm-ag--run-other-window-action)) keymap (M-return keymap (104 . helm-minibuffer-history) (105 . helm-minibuffer-history) (97 . helm-toggle-all-marks) (98 "bookmarks" keymap (109 . helm-ff-bookmark-set) (98 . bookmark-jump))) (100663328 . helm-toggle-all-marks) (C-i . undo-tree-redo) (C-end . helm-end-of-buffer) (C-home . helm-beginning-of-buffer) (end) (home) (33554457 . helm-copy-to-buffer) (25 . helm-kill-selection-and-quit) (4 . helm-buffer-run-kill-persistent) (C-iso-lefttab . helm-follow-action-backward) (26 . helm-select-action) (tab . helm-execute-persistent-action) (33554440 . describe-key) (33554443 . helm-follow-action-backward) (33554442 . helm-follow-action-forward) (17 . ace-jump-helm-line) (f13 lambda nil (interactive) (helm-select-nth-action 12)) (f12 lambda nil (interactive) (helm-select-nth-action 11)) (f11 lambda nil (interactive) (helm-select-nth-action 10)) (f10 lambda nil (interactive) (helm-select-nth-action 9)) (f9 lambda nil (interactive) (helm-select-nth-action 8)) (f8 lambda nil (interactive) (helm-select-nth-action 7)) (f7 lambda nil (interactive) (helm-select-nth-action 6)) (f6 lambda nil (interactive) (helm-select-nth-action 5)) (f5 lambda nil (interactive) (helm-select-nth-action 4)) (f4 lambda nil (interactive) (helm-select-nth-action 3)) (f3 lambda nil (interactive) (helm-select-nth-action 2)) ...) nil helm-ag--helm-history))
helm(:sources helm-source-do-ag :buffer "helm-ag" :keymap (keymap (C-p . helm-ag--previous-file) (C-n . helm-ag--next-file) (left) (right) (M-return keymap (115 . helm-ag--run-save-buffer) (101 . helm-ag-edit)) (3 keymap (63 . helm-ag--do-ag-help)) (12 . helm-ag--do-ag-up-one-level) keymap (normal-state keymap "Auxiliary keymap for Normal stat..." (83 keymap (80 keymap ...))) (left . helm-ag--previous-file) (right . helm-ag--next-file) (24 keymap (19 . helm-ag--run-save-buffer)) (12 . helm-ag--up-one-level) (3 keymap (60 . helm-ag--previous-file) (62 . helm-ag--next-file) (63 . helm-ag-help) (5 . helm-ag-edit) (111 . helm-ag--run-other-window-action)) keymap (M-return keymap (104 . helm-minibuffer-history) (105 . helm-minibuffer-history) (97 . helm-toggle-all-marks) (98 "bookmarks" keymap (109 . helm-ff-bookmark-set) (98 . bookmark-jump))) (100663328 . helm-toggle-all-marks) (C-i . undo-tree-redo) (C-end . helm-end-of-buffer) (C-home . helm-beginning-of-buffer) (end) (home) (33554457 . helm-copy-to-buffer) (25 . helm-kill-selection-and-quit) (4 . helm-buffer-run-kill-persistent) (C-iso-lefttab . helm-follow-action-backward) (26 . helm-select-action) (tab . helm-execute-persistent-action) (33554440 . describe-key) (33554443 . helm-follow-action-backward) (33554442 . helm-follow-action-forward) ...) :input "git-gutter:linum-get-overlay" :history helm-ag--helm-history)
helm-do-ag--helm(nil nil)
helm-do-ag(nil nil nil)
helm-do-ag-buffers()

Only literal replacement is intended in helm-ag--abbreviate-file-name,
so prevent backspace parsing by passing LITERAL as true.

E.g. if rg is used as helm-ag-base-command, it can output backslashes in
its search results for binary files, so an error or unintended replacing
behavior could occur.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant