Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #442 - Prevent crash when cursor is in the middle of a UTF sequence #443

Merged
merged 2 commits into from
Feb 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/dcd/server/autocomplete/complete.d
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,20 @@ AutocompleteResponse dotCompletion(T)(T beforeTokens, const(Token)[] tokenArray,
// of at the end
auto t = beforeTokens[$ - 1];
if (cursorPosition - t.index >= 0 && cursorPosition - t.index <= t.text.length)
{
partial = t.text[0 .. cursorPosition - t.index];
significantTokenType = tok!"identifier";
// issue 442 - prevent `partial` to start in the middle of a MBC
// since later there's a non-nothrow call to `toUpper`
import std.utf : validate, UTFException;
try validate(partial);
catch (UTFException)
{
import std.experimental.logger : warning;
warning("cursor positioned within a UTF sequence");
partial = "";
}
}
significantTokenType = partial.length ? tok!"identifier" : tok!"";
beforeTokens = beforeTokens[0 .. $ - 1];
}
else if (beforeTokens.length >= 2 && beforeTokens[$ - 1] == tok!".")
Expand Down
Empty file.
1 change: 1 addition & 0 deletions tests/tc_middle_of_utf/file.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ß
5 changes: 5 additions & 0 deletions tests/tc_middle_of_utf/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set -e
set -u

../../bin/dcd-client $1 file.d -c1 > actual1.txt
diff actual1.txt expected1.txt