[Ironruby-core] Linebreak issue with clr strings manipulated by Ruby code

Aldinei Sampaio aldinei.sampaio at gmail.com
Fri Feb 25 07:35:10 EST 2011

Hi, guys. Sorry if I am posting this in the wrong place, but I need
some kind of direction here.

I isolated my problem in the following UnitTest in Visual Basic:

Public Sub LineBreakProblem()
    Const SCRIPT = "print System::String.Format('Line1{0}Line2',

    Dim engine = IronRuby.Ruby.CreateEngine()
    Dim stream = New IO.MemoryStream
    Dim writer = New IO.StreamWriter(stream)
    engine.Runtime.IO.SetOutput(stream, writer)
    Dim source = engine.CreateScriptSourceFromString(SCRIPT, "Script",

    stream.Position = 0
    Dim actual = (New IO.StreamReader(stream)).ReadToEnd()

    Dim expected = String.Format("Line1{0}Line2", Environment.NewLine)

    Assert.AreEqual(expected, actual)
End Sub

As you can see, i am running this Ruby code:

print System::String.Format('Line1{0}Line2', System::Environment.NewLine)

And then I am using the engine.Runtime.IO.SetOutput to get back the
result generated by the "print" statement. System.Environment.NewLine
returns the char combination CR + LF.

The "expected" variable will contain: "Line1" + CR + LF + "Line2".
The "actual" variable receive the value "Line1" + CR + LF + CR + LF + "Line2"

Seems that all the linebreaks are doubled when using the CLR string
with the "print" statement.

Any suggestion that you can give me to resolve or work around this
problem will be much appreciated.

More information about the Ironruby-core mailing list