From e2841dc26cb0918528b622a6d0994984a75fde95 Mon Sep 17 00:00:00 2001 From: Jacob Wahlgren Date: Tue, 22 Sep 2015 00:35:36 +0200 Subject: [PATCH 1/2] Don't allow :s delimiters not allowed by vim "Instead of the '/' which surrounds the pattern and replacement string, you can use any other single-byte character, but not an alphanumeric character, '\', '"'' or '|'." - http://vimdoc.sourceforge.net/htmldoc/change.html#:substitute --- lib/ex.coffee | 4 ++-- spec/ex-commands-spec.coffee | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/ex.coffee b/lib/ex.coffee index e259c90..684b2f6 100644 --- a/lib/ex.coffee +++ b/lib/ex.coffee @@ -199,9 +199,9 @@ class Ex substitute: (range, args) -> args = args.trimLeft() delim = args[0] - if /[a-z]/i.test(delim) + if /[a-z1-9\\"|]/i.test(delim) 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}") spl = [] args_ = args[1..] diff --git a/spec/ex-commands-spec.coffee b/spec/ex-commands-spec.coffee index 803aa57..7bf10af 100644 --- a/spec/ex-commands-spec.coffee +++ b/spec/ex-commands-spec.coffee @@ -453,7 +453,14 @@ describe "the commands", -> keydown(':') submitNormalModeInputText(':substitute nanxngi') expect(atom.notifications.notifications[0].message).toEqual( - "Command error: Regular expressions can't be delimited by letters") + "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 numbers", -> + keydown(':') + submitNormalModeInputText(':substitute 1a1x1gi') + expect(atom.notifications.notifications[0].message).toEqual( + "Command error: Regular expressions can't be delimited by alphanumeric characters, '\\', '\"' or '|'") expect(editor.getText()).toEqual('abcaABC\ndefdDEF\nabcaABC') describe "capturing groups", -> From 77d3fa46d53ab7db4deedd5936940eb7e98f5c68 Mon Sep 17 00:00:00 2001 From: Jacob Wahlgren Date: Tue, 22 Sep 2015 00:50:21 +0200 Subject: [PATCH 2/2] Refactor illegal delimiters specs --- spec/ex-commands-spec.coffee | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/spec/ex-commands-spec.coffee b/spec/ex-commands-spec.coffee index 7bf10af..a4813b5 100644 --- a/spec/ex-commands-spec.coffee +++ b/spec/ex-commands-spec.coffee @@ -449,19 +449,19 @@ describe "the commands", -> submitNormalModeInputText(':%substitute/abc/ghi/ig') expect(editor.getText()).toEqual('ghiaghi\ndefdDEF\nghiaghi') - it "can't be delimited by letters", -> - keydown(':') - submitNormalModeInputText(':substitute nanxngi') - expect(atom.notifications.notifications[0].message).toEqual( - "Command error: Regular expressions can't be delimited by alphanumeric characters, '\\', '\"' or '|'") - expect(editor.getText()).toEqual('abcaABC\ndefdDEF\nabcaABC') + describe "illegal delimiters", -> + test = (delim) -> + keydown(':') + submitNormalModeInputText(":substitute #{delim}a#{delim}x#{delim}gi") + expect(atom.notifications.notifications[0].message).toEqual( + "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 numbers", -> - keydown(':') - submitNormalModeInputText(':substitute 1a1x1gi') - expect(atom.notifications.notifications[0].message).toEqual( - "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", -> beforeEach ->