Fix Issue 18328 - algorithm.startsWith can compare narrow string lengths in more circumstances

This commit is contained in:
Nathan Sashihara 2018-01-29 21:24:37 -05:00
parent 2f25cdf076
commit b4ad39a8b6

View file

@ -4210,9 +4210,10 @@ if (isInputRange!R1 &&
enum isDefaultPred = false;
//Note: While narrow strings don't have a "true" length, for a narrow string to start with another
//narrow string *of the same type*, it must have *at least* as many code units.
//narrow string of the same type or wider, it must have *at least* as many code units.
static if ((hasLength!R1 && hasLength!R2) ||
(isNarrowString!R1 && isNarrowString!R2 && ElementEncodingType!R1.sizeof == ElementEncodingType!R2.sizeof))
((hasLength!R1 || isNarrowString!R1) && (hasLength!R2 || isNarrowString!R2)
&& (ElementEncodingType!R1.sizeof <= ElementEncodingType!R2.sizeof)))
{
if (haystack.length < needle.length)
return false;