www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18781] New: std.string.replace: RangeError when replacing

https://issues.dlang.org/show_bug.cgi?id=18781

          Issue ID: 18781
           Summary: std.string.replace: RangeError when replacing with
                    inconsistent string types
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: dhasenan gmail.com

void main()
{
    import std.string : replace;
    "”quote”"w.replace("”", `"`);
}


This crashes with:

core.exception.RangeError /usr/include/dmd/phobos/std/array.d(2167): Range
violation
----------------
??:? _d_arrayboundsp [0x42c4ee]
/usr/include/dmd/phobos/std/array.d:2167 pure  safe void
std.array.replaceInto!(immutable(wchar),
std.array.Appender!(immutable(wchar)[]).Appender, immutable(char)[],
immutable(char)[]).replaceInto(std.array.Appender!(immutable(wchar)[]).Appender,
immutable(wchar)[], immutable(char)[], immutable(char)[]) [0x42b107]
/usr/include/dmd/phobos/std/array.d:2098 pure  safe immutable(wchar)[]
std.array.replace!(immutable(wchar), immutable(char)[],
immutable(char)[]).replace(immutable(wchar)[], immutable(char)[],
immutable(char)[]) [0x42a01b]
wstringcrash.d:4 _Dmain [0x429669]


Note that the string operated on is a wstring, and the replacements are
strings.

Conversely, calling `replace(string, wstring, wstring)` tends to result in
invalid UTF-8 sequences:

    "☃ world.".replace("☃"w, `:`w);

std.utf.UTFException /usr/include/dmd/phobos/std/utf.d(1380): Invalid UTF-8
sequence (at index 2)

--
Apr 19 2018