Skip to content

Commit

Permalink
Handle unexpected newlines in rg --type-list more gracefully
Browse files Browse the repository at this point in the history
Fix #68
  • Loading branch information
dajva committed Dec 15, 2019
1 parent aea2a87 commit 65c5b2b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 5 additions & 4 deletions rg.el
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,13 @@ are command line flags to use for the search."
pattern
(if (rg-is-custom-file-pattern files) "custom" files))))

(defun rg-invoke-rg-type-list ()
"Invokes rg --type-list and return the result."
(shell-command-to-string (concat (rg-executable) " --type-list")))

(defun rg-list-builtin-type-aliases ()
"Invokes rg --type-list and puts the result in an alist."
(let ((type-list (nbutlast (split-string
(shell-command-to-string
(concat (rg-executable) " --type-list"))
"\n") 1)))
(let ((type-list (delete "" (split-string (rg-invoke-rg-type-list) "\n"))))
(mapcar
(lambda (type-alias)
(setq type-alias (split-string type-alias ":" t))
Expand Down
7 changes: 7 additions & 0 deletions test/rg.el-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,13 @@ Test `:flags' directive."
(should (equal (cadr (assq 'dir dir)) 'read-directory-name))
(should (equal (caar (cddr (assq 'flags flags))) 'read-string))))

(ert-deftest rg-uni/builtin-aliases-empty-strings ()
"Test that empty strings in builtin aliases are filtered out."
(cl-letf (((symbol-function #'rg-invoke-rg-type-list)
(lambda () "\n\n foo: *.foo,*.fo\n\n bar: *.bar,*.ba\n")))
(equal (rg-list-builtin-type-aliases)
'(("foo" . "*.foo *.fo") ("bar" . "*.bar *.ba")))))


;; Integration tests

Expand Down

0 comments on commit 65c5b2b

Please sign in to comment.