From ab945ab15d14ae698196c86474ba75893982f63b Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Tue, 27 Mar 2018 16:14:04 -0400 Subject: [PATCH 1/3] Unit test for match behavior of \r and . --- test/js/text-buffer.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/js/text-buffer.test.js b/test/js/text-buffer.test.js index e14fc102..bfde436b 100644 --- a/test/js/text-buffer.test.js +++ b/test/js/text-buffer.test.js @@ -1187,6 +1187,11 @@ describe('TextBuffer', () => { Range(Point(5, 0), Point(5, 0)) ]) }) + + it('does not match \\r with .', () => { + const buffer = new TextBuffer('\r') + assert.lengthOf(buffer.findAllInRangeSync(/./), 0) + }) }) describe('.findAndMarkAllSync', () => { From bc5309f6d46df29f70f81a3b506aecad9ba226dd Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Tue, 27 Mar 2018 16:14:36 -0400 Subject: [PATCH 2/3] Configure pcre2 to always treat \r and \n as newlines --- src/core/regex.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/regex.cc b/src/core/regex.cc index 8e51e5a6..6ab6d07b 100644 --- a/src/core/regex.cc +++ b/src/core/regex.cc @@ -48,6 +48,9 @@ Regex::Regex(const char16_t *pattern, uint32_t pattern_length, u16string *error_ u16string final_pattern = preprocess_pattern(pattern, pattern_length); + pcre2_compile_context *context = pcre2_compile_context_create(nullptr); + pcre2_set_newline(context, PCRE2_NEWLINE_ANY); + int error_number = 0; size_t error_offset = 0; uint32_t options = PCRE2_MULTILINE; @@ -58,8 +61,9 @@ Regex::Regex(const char16_t *pattern, uint32_t pattern_length, u16string *error_ options, &error_number, &error_offset, - nullptr + context ); + pcre2_compile_context_free(context); if (!code) { uint16_t message_buffer[256]; From d95847cb5fe0a64b67d2cb2acb36d67b17314a9b Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Tue, 27 Mar 2018 16:51:53 -0400 Subject: [PATCH 3/3] Pass a Range argument --- test/js/text-buffer.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/js/text-buffer.test.js b/test/js/text-buffer.test.js index bfde436b..9d14b07b 100644 --- a/test/js/text-buffer.test.js +++ b/test/js/text-buffer.test.js @@ -1190,7 +1190,7 @@ describe('TextBuffer', () => { it('does not match \\r with .', () => { const buffer = new TextBuffer('\r') - assert.lengthOf(buffer.findAllInRangeSync(/./), 0) + assert.lengthOf(buffer.findAllInRangeSync(/./, Range(Point(0, 0), Point(Infinity, Infinity))), 0) }) })