Skip to content

Commit

Permalink
Be defensive about user input
Browse files Browse the repository at this point in the history
  • Loading branch information
srishanbhattarai committed Sep 19, 2018
1 parent ab07678 commit de41536
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ BharyangAsc
BharyangDesc
BharyangGroup
```
The `Bharyang` command uses a configuration value to determine whether the sort should be ascending ("asc") or descending ("desc"). It is ascending by default. Configure it using:
The `Bharyang` command uses a configuration value to determine default sort type. The value can be one of `asc`, `desc` or `group`. For example, to set it to `desc`:
```vim
let g:bharyang_default_sort_type="desc"
```
Expand Down
7 changes: 7 additions & 0 deletions plugin/bharyang-vim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ let s:group = "group"
" =========================

function! s:Bharyang(type) range
" Check if the type is valid, because the user exposed global sort type might change it to something else.
if a:type !=# s:asc && a:type !=# s:desc && a:type !=# s:group
echoe "Sort type ".a:type." is not compatible with Bharyang. Use one of `asc`, `desc` or `group`."

return
endif

if executable('bharyang')
let l:sortedlines = s:SortLines(a:type, getline(a:firstline, a:lastline))
let l:totallines = a:lastline - a:firstline + 1
Expand Down

0 comments on commit de41536

Please sign in to comment.