Bug 11374 – Wrong UTF-8 decoding when calling File.readln(buf) with typeof(buf) == string.

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-10-28T15:54:00Z
Last change time
2013-10-30T15:44:43Z
Assigned to
nobody
Creator
joanbrugueram

Comments

Comment #0 by joanbrugueram — 2013-10-28T15:54:27Z
I'm sorry if this is not really a bug but just some ultra-obscure quirk. Anyway, doing something like: string buf; stdin.readln(buf); Appears to work, but seems to decode some characters wrong (consistently). Using "char[] buf;" or "stdin.readln()" both work. Here's a more complete test case: *************************************************************** import std.stdio; void main() { ubyte[] weirdcharacterbytes = [0xf0, 0x90, 0xa4, 0x80]; string weirdcharacter = cast(string)weirdcharacterbytes; { auto f = File("weirdcharacter.txt", "wb"); f.rawWrite(weirdcharacterbytes); } { auto f = File("weirdcharacter.txt", "r"); string s = f.readln(); writeln(s == weirdcharacter ? "PASS" : "FAIL"); } { auto f = File("weirdcharacter.txt", "r"); char[] s; f.readln(s); writeln(s == weirdcharacter ? "PASS" : "FAIL"); } { auto f = File("weirdcharacter.txt", "r"); string s; f.readln(s); writeln(s == weirdcharacter ? "PASS" : "FAIL"); } } *************************************************************** PASS PASS FAIL *************************************************************** Thanks.
Comment #1 by mk — 2013-10-28T16:40:27Z
Your example doesn't compile in the git-head. See bug 10517.
Comment #2 by joanbrugueram — 2013-10-29T15:59:32Z
(In reply to comment #1) > Your example doesn't compile in the git-head. See bug 10517. Thank you, it appears that this bug has indeed been fixed. Also, this may sound like a rant or blaming someone else, and it very likely is, but the fact that the source link in the Phobos 2.063.2 documentation points to the prerelease version didn't help (obvious in hindsight, but no wonder I couldn't figure out which overload was being called and gave up). Also, I did indeed run a bugzilla search for 'readln', but the default filter doesn't display closed bugs, so I also couldn't find the closed bug you linked.
Comment #3 by mk — 2013-10-30T15:44:43Z
*** This issue has been marked as a duplicate of issue 10517 ***