From 6aecbbebfd2e2dbe0714242fb6c4b83d40bf22da Mon Sep 17 00:00:00 2001 From: Florian Walch Date: Tue, 23 Dec 2014 12:24:54 +0100 Subject: [PATCH 1/3] vim-patch:7.4.483 Problem: A 0x80 byte is not handled correctly in abbreviations. Solution: Unescape special characters. Add a test. (Christian Brabandt) https://code.google.com/p/vim/source/detail?r=v7-4-483 --- src/nvim/getchar.c | 15 ++++++++++++++- src/nvim/version.c | 2 +- test/functional/legacy/mapping_spec.lua | 24 ++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 test/functional/legacy/mapping_spec.lua diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 882d30388c..e9761a7e5d 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -15,6 +15,7 @@ * mappings and abbreviations */ +#include #include #include #include @@ -3572,6 +3573,7 @@ int check_abbr(int c, char_u *ptr, int col, int mincol) int clen = 0; /* length in characters */ int is_id = TRUE; int vim_abbr; + int qlen; /* length of q, CSI/K_SPECIAL unescaped */ if (typebuf.tb_no_abbr_cnt) /* abbrev. are not recursive */ return FALSE; @@ -3634,12 +3636,23 @@ int check_abbr(int c, char_u *ptr, int col, int mincol) mp = mp2; mp2 = NULL; } + qlen = mp->m_keylen; + if (vim_strbyte(mp->m_keys, K_SPECIAL) != NULL) { + char_u *q = vim_strsave(mp->m_keys); + + /* might have CSI escaped mp->m_keys */ + if (q != NULL) { + vim_unescape_csi(q); + qlen = STRLEN(q); + free(q); + } + } for (; mp; mp->m_next == NULL ? (mp = mp2, mp2 = NULL) : (mp = mp->m_next)) { /* find entries with right mode and keys */ if ( (mp->m_mode & State) - && mp->m_keylen == len + && qlen == len && !STRNCMP(mp->m_keys, ptr, (size_t)len)) break; } diff --git a/src/nvim/version.c b/src/nvim/version.c index 91f160d83f..b2598ada50 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -255,7 +255,7 @@ static int included_patches[] = { //486, //485, //484 NA - //483, + 483, //482 NA //481 NA //480 NA diff --git a/test/functional/legacy/mapping_spec.lua b/test/functional/legacy/mapping_spec.lua new file mode 100644 index 0000000000..0cb270f701 --- /dev/null +++ b/test/functional/legacy/mapping_spec.lua @@ -0,0 +1,24 @@ +-- Test for mappings and abbreviations + +local helpers = require('test.functional.helpers') +local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert +local execute, expect = helpers.execute, helpers.expect + +describe('mapping', function() + setup(clear) + + it('is working', function() + insert([[ + test starts here: + ]]) + + -- Abbreviations with р (0x80) should work. + execute('inoreab чкпр vim') + feed('GAчкпр ') + + -- Assert buffer contents. + expect([[ + test starts here: + vim]]) + end) +end) From 0b192bf990927657f6f4c6a4a4e406b38bbba01e Mon Sep 17 00:00:00 2001 From: Florian Walch Date: Tue, 23 Dec 2014 12:40:23 +0100 Subject: [PATCH 2/3] vim-patch:7.4.485 Problem: Abbreviations don't work. (Toothpik) Solution: Move the length computation inside the for loop. Compare against the unescaped key. https://code.google.com/p/vim/source/detail?r=v7-4-485 --- src/nvim/getchar.c | 35 ++++++++++++++++++++--------------- src/nvim/version.c | 2 +- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index e9761a7e5d..39227cc199 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -3573,7 +3573,6 @@ int check_abbr(int c, char_u *ptr, int col, int mincol) int clen = 0; /* length in characters */ int is_id = TRUE; int vim_abbr; - int qlen; /* length of q, CSI/K_SPECIAL unescaped */ if (typebuf.tb_no_abbr_cnt) /* abbrev. are not recursive */ return FALSE; @@ -3636,25 +3635,31 @@ int check_abbr(int c, char_u *ptr, int col, int mincol) mp = mp2; mp2 = NULL; } - qlen = mp->m_keylen; - if (vim_strbyte(mp->m_keys, K_SPECIAL) != NULL) { - char_u *q = vim_strsave(mp->m_keys); - - /* might have CSI escaped mp->m_keys */ - if (q != NULL) { - vim_unescape_csi(q); - qlen = STRLEN(q); - free(q); - } - } for (; mp; mp->m_next == NULL ? (mp = mp2, mp2 = NULL) : (mp = mp->m_next)) { + int qlen = mp->m_keylen; + char_u *q = mp->m_keys; + int match; + + if (vim_strbyte(mp->m_keys, K_SPECIAL) != NULL) { + /* might have CSI escaped mp->m_keys */ + q = vim_strsave(mp->m_keys); + if (q != NULL) { + vim_unescape_csi(q); + qlen = (int)STRLEN(q); + } + } /* find entries with right mode and keys */ - if ( (mp->m_mode & State) - && qlen == len - && !STRNCMP(mp->m_keys, ptr, (size_t)len)) + match = (mp->m_mode & State) + && qlen == len + && !STRNCMP(q, ptr, (size_t)len); + if (q != mp->m_keys) { + free(q); + } + if (match) { break; + } } if (mp != NULL) { /* diff --git a/src/nvim/version.c b/src/nvim/version.c index b2598ada50..473d4f8549 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -253,7 +253,7 @@ static int included_patches[] = { //488, //487, //486, - //485, + 485, //484 NA 483, //482 NA From e06159e6ae907c50e2f36ad491297d23cb97487a Mon Sep 17 00:00:00 2001 From: Florian Walch Date: Tue, 23 Dec 2014 13:01:14 +0100 Subject: [PATCH 3/3] vim-patch:7.4.488 Problem: test_mapping fails for some people. Solution: Set the 'encoding' option. (Ken Takata) https://code.google.com/p/vim/source/detail?r=v7-4-488 --- src/nvim/version.c | 2 +- test/functional/legacy/mapping_spec.lua | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/nvim/version.c b/src/nvim/version.c index 473d4f8549..5542400e02 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -250,7 +250,7 @@ static int included_patches[] = { 491, //490, 489, - //488, + 488, //487, //486, 485, diff --git a/test/functional/legacy/mapping_spec.lua b/test/functional/legacy/mapping_spec.lua index 0cb270f701..46d29d1692 100644 --- a/test/functional/legacy/mapping_spec.lua +++ b/test/functional/legacy/mapping_spec.lua @@ -12,6 +12,8 @@ describe('mapping', function() test starts here: ]]) + execute('set encoding=utf-8') + -- Abbreviations with р (0x80) should work. execute('inoreab чкпр vim') feed('GAчкпр ')