Skip to content
This repository was archived by the owner on Jun 5, 2019. It is now read-only.

Commit d0fc72a

Browse files
committed
Merge pull request #198 from mortezag/fixReadline
Fix Peek method in StreamReader
2 parents 11e6037 + 1bff561 commit d0fc72a

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

Framework/Core/System/IO/StreamReader.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ public override int Peek()
8787
int nextChar;
8888

8989
// If buffer need refresh take into account max UTF8 bytes if the next character is UTF8 encoded
90-
if ((m_curBufPos == (m_curBufLen-1)) ||
90+
// Note: In some occasions, m_curBufPos may go beyond m_curBufLen-1 (for example, when trying to peek after reading the last character of the buffer), so we need to refresh the buffer in these cases too
91+
if ((m_curBufPos >= (m_curBufLen-1)) ||
9192
((m_buffer[m_curBufPos + 1] & 0x80) != 0 &&
9293
(m_curBufPos + 3 >= m_curBufLen)))
9394
{

Test/Platform/Tests/CLR/System/IO/FileStreamTests.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,5 +635,51 @@ public MFTestResults FileStreamTest_FileAccessAndFileShare()
635635

636636
return (pass)? MFTestResults.Pass : MFTestResults.Fail;
637637
}
638+
639+
[TestMethod]
640+
public MFTestResults Test_Fix2048()
641+
{
642+
// This test was created for http://netmf.codeplex.com/workitem/2048
643+
const string file = "foo.txt";
644+
MFTestResults result = MFTestResults.Pass;
645+
try
646+
{
647+
const string content = "\"this is param0 HH:MM:SS-YY-mm-dd\", \"this is param1\", \"this is param2\", \"this is param3\",MAXMOISTURE=4.5,MINLEVEL=10,WATERACTIVE=True";
648+
649+
StreamWriter sw = new StreamWriter(file);
650+
651+
for (int i = 0; i < 616; i++)
652+
{
653+
sw.WriteLine(content);
654+
}
655+
656+
sw.Close();
657+
658+
StreamReader sr = new StreamReader(file);
659+
string str = sr.ReadLine();
660+
661+
if(str != content)
662+
{
663+
result = MFTestResults.Fail;
664+
}
665+
666+
sr.Close();
667+
}
668+
catch (Exception ex)
669+
{
670+
result = MFTestResults.Fail;
671+
Log.Exception("Unexpected Exception", ex);
672+
}
673+
finally
674+
{
675+
try
676+
{
677+
File.Delete(file);
678+
}
679+
catch { }
680+
}
681+
682+
return result;
683+
}
638684
}
639685
}

0 commit comments

Comments
 (0)