Merge pull request #443 from dlang-community/issue-442

fix #442 - Prevent crash when cursor is in the middle of a UTF sequence
merged-on-behalf-of: Sebastian Wilzbach <sebi.wilzbach@gmail.com>
This commit is contained in:
The Dlang Bot 2018-02-24 13:52:00 +01:00 committed by GitHub
commit a6804db037
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 1 deletions

View File

@ -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!".")

View File

View File

@ -0,0 +1 @@
ß

5
tests/tc_middle_of_utf/run.sh Executable file
View File

@ -0,0 +1,5 @@
set -e
set -u
../../bin/dcd-client $1 file.d -c1 > actual1.txt
diff actual1.txt expected1.txt