Skip to content

Commit 7e70c26

Browse files
author
Basile Burg
committed
fix #442 - Prevent crash when cursor is in the middle of a UTF sequence
1 parent d6ce0a2 commit 7e70c26

4 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/dcd/server/autocomplete/complete.d

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,15 @@ AutocompleteResponse dotCompletion(T)(T beforeTokens, const(Token)[] tokenArray,
114114
// of at the end
115115
auto t = beforeTokens[$ - 1];
116116
if (cursorPosition - t.index >= 0 && cursorPosition - t.index <= t.text.length)
117+
{
117118
partial = t.text[0 .. cursorPosition - t.index];
118-
significantTokenType = tok!"identifier";
119+
// issue 442 - prevent `partial` to start in the middle of a MBC
120+
// since later there's a non-nothrow call to `toUpper`
121+
import std.utf : validate, UTFException;
122+
try validate(partial);
123+
catch (UTFException) partial = "";
124+
}
125+
significantTokenType = partial.length ? tok!"identifier" : tok!"";
119126
beforeTokens = beforeTokens[0 .. $ - 1];
120127
}
121128
else if (beforeTokens.length >= 2 && beforeTokens[$ - 1] == tok!".")

tests/tc_middle_of_utf/expected1.txt

Whitespace-only changes.

tests/tc_middle_of_utf/file.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ß

tests/tc_middle_of_utf/run.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
set -e
2+
set -u
3+
4+
../../bin/dcd-client $1 file.d -c1 > actual1.txt
5+
diff actual1.txt expected1.txt

0 commit comments

Comments
 (0)