Bug 18781 – std.string.replace: RangeError when replacing with inconsistent string types

Status
NEW
Severity
normal
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-04-20T00:05:42Z
Last change time
2024-12-01T16:33:33Z
Assigned to
No Owner
Creator
Neia Neutuladh
Moved to GitHub: phobos#10331 →

Comments

Comment #0 by dhasenan — 2018-04-20T00:05:42Z
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)
Comment #1 by ag0aep6g — 2018-04-20T08:04:21Z
*** Issue 18783 has been marked as a duplicate of this issue. ***
Comment #2 by ag0aep6g — 2018-04-20T08:09:44Z
Related forum thread: https://forum.dlang.org/post/[email protected] If you make a bug report for a forum post, please leave a link to the bug in the forum thread, so that we don't get duplicates.
Comment #3 by robert.schadek — 2024-12-01T16:33:33Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10331 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB