Merge pull request #102 from jacwah/sub-sep

Don't allow :s delimiters not allowed by vim
This commit is contained in:
Loic Nageleisen 2015-09-23 20:30:39 +02:00
commit 5773c8f47b
2 changed files with 15 additions and 8 deletions

View file

@ -199,9 +199,9 @@ class Ex
substitute: (range, args) -> substitute: (range, args) ->
args = args.trimLeft() args = args.trimLeft()
delim = args[0] delim = args[0]
if /[a-z]/i.test(delim) if /[a-z1-9\\"|]/i.test(delim)
throw new CommandError( throw new CommandError(
"Regular expressions can't be delimited by letters") "Regular expressions can't be delimited by alphanumeric characters, '\\', '\"' or '|'")
delimRE = new RegExp("[^\\\\]#{delim}") delimRE = new RegExp("[^\\\\]#{delim}")
spl = [] spl = []
args_ = args[1..] args_ = args[1..]

View file

@ -449,12 +449,19 @@ describe "the commands", ->
submitNormalModeInputText(':%substitute/abc/ghi/ig') submitNormalModeInputText(':%substitute/abc/ghi/ig')
expect(editor.getText()).toEqual('ghiaghi\ndefdDEF\nghiaghi') expect(editor.getText()).toEqual('ghiaghi\ndefdDEF\nghiaghi')
it "can't be delimited by letters", -> describe "illegal delimiters", ->
keydown(':') test = (delim) ->
submitNormalModeInputText(':substitute nanxngi') keydown(':')
expect(atom.notifications.notifications[0].message).toEqual( submitNormalModeInputText(":substitute #{delim}a#{delim}x#{delim}gi")
"Command error: Regular expressions can't be delimited by letters") expect(atom.notifications.notifications[0].message).toEqual(
expect(editor.getText()).toEqual('abcaABC\ndefdDEF\nabcaABC') "Command error: Regular expressions can't be delimited by alphanumeric characters, '\\', '\"' or '|'")
expect(editor.getText()).toEqual('abcaABC\ndefdDEF\nabcaABC')
it "can't be delimited by letters", -> test 'n'
it "can't be delimited by numbers", -> test '3'
it "can't be delimited by '\\'", -> test '\\'
it "can't be delimited by '\"'", -> test '"'
it "can't be delimited by '|'", -> test '|'
describe "capturing groups", -> describe "capturing groups", ->
beforeEach -> beforeEach ->