fix #442 - Prevent crash when cursor is in the middle of a UTF sequence
This commit is contained in:
parent
d6ce0a2f7b
commit
7e70c26faa
|
@ -114,8 +114,15 @@ AutocompleteResponse dotCompletion(T)(T beforeTokens, const(Token)[] tokenArray,
|
||||||
// of at the end
|
// of at the end
|
||||||
auto t = beforeTokens[$ - 1];
|
auto t = beforeTokens[$ - 1];
|
||||||
if (cursorPosition - t.index >= 0 && cursorPosition - t.index <= t.text.length)
|
if (cursorPosition - t.index >= 0 && cursorPosition - t.index <= t.text.length)
|
||||||
|
{
|
||||||
partial = t.text[0 .. cursorPosition - t.index];
|
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) partial = "";
|
||||||
|
}
|
||||||
|
significantTokenType = partial.length ? tok!"identifier" : tok!"";
|
||||||
beforeTokens = beforeTokens[0 .. $ - 1];
|
beforeTokens = beforeTokens[0 .. $ - 1];
|
||||||
}
|
}
|
||||||
else if (beforeTokens.length >= 2 && beforeTokens[$ - 1] == tok!".")
|
else if (beforeTokens.length >= 2 && beforeTokens[$ - 1] == tok!".")
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
ß
|
|
@ -0,0 +1,5 @@
|
||||||
|
set -e
|
||||||
|
set -u
|
||||||
|
|
||||||
|
../../bin/dcd-client $1 file.d -c1 > actual1.txt
|
||||||
|
diff actual1.txt expected1.txt
|
Loading…
Reference in New Issue