Well, actually, it isn't as easy as that. The fundamental problem isn't that Ruby is 'changing' something on win32 but not on *nix. The problem is that Ruby's internal newline format happens to be the same as *nix (for some _VERY_ strange reason... =)
What this means is that Ruby will change FROM line-separator into \n regardless of platform. But on *nix this doesn't matter, it's from \n into \n. On win32 it's \r\n into \n, but only for non-binary reading/writing. I'm also pretty sure that this behaviour will be \r into \n on MacOS X. I tend to agree with this policy for reading, but not for writing, but I guess that isn't really the issue. The problem with rails and newlines isn't really a problem with rails, it's a problem with regexps. Rails uses ERb for templating, and ERb uses a StringScanner, which uses regexps to find the first newline, or EOF, whatever comes first. On my win32 box, this results in the wrong behaviour, for some reason. So I'm pretty sure it would be hard to change that behaviour without actually reading and writing newlines as C Ruby does it. /O ----- Original Message ----- From: Charles O Nutter <[EMAIL PROTECTED]> Date: Sunday, June 25, 2006 10:15 pm Subject: Re: [Jruby-devel] Newline problem. To: [EMAIL PROTECTED], jruby-devel@lists.sourceforge.net > Your patch seems to be the right way to go once we work the kinks > out. I > poked around and found a number of threads discussing how win32 > ruby reads > \r\n as \n and write \n as \r\n. Personally, I think this is a bad > idea, but > it does limit the areas we would need to patch. There's a trick, > however. > Java as a platform is somewhere between windows and unix. Some of > theseproblems we see may be because there's really no in-between in > Ruby. You're > either running on a win32 ruby or on a unix ruby, and so most > libraries and > applications make assumptions one way or the other depending on > platform.For many cases, we need scripts to act both like unix and > like ruby for > various things. > > So anyway, back to this issue. With newlines, Java is acting more > like unix, > not modifying incoming or outgoing line terminators in any way. > This is, in > my opinion, a better way to handle things, especially considering > the issues > you run into with byte indexing a file with \r\n's in it. Besides > the option > of doing newline conversions on read and write, there's another > choice:figure out why it matters to scripts under java-win32 JRuby > and eliminate > that. Obviously Rails is doing something that expects \r\n to be > convertedto \n, but it only makes that assumption under windows. > And there's a > related question: how can Rails behavior under JRuby differ between > unix and > windows? Would it be possible to make it always look like unix (as > we sorta > do already for file path separators)? > > On 6/25/06, Ola Bini <[EMAIL PROTECTED]> wrote: > > > > Hi > > > > Yes, that's what I gathered too. And my patch also does it that way, > > comparing the current line.separator to \n and only changing lines > > dynamically then. > > So, the fun thing now is to see Thomas output on his C and JRuby. > > > > /O > > > > ----- Original Message ----- > > From: Charles O Nutter <[EMAIL PROTECTED]> > > Date: Sunday, June 25, 2006 9:22 pm > > Subject: Re: [Jruby-devel] Newline problem. > > To: [EMAIL PROTECTED], jruby-devel@lists.sourceforge.net > > > > > Here's what I get in x86-64 Linux: > > > > > > [EMAIL PROTECTED]:~/testrails/test4# ruby ~/Desktop/testLineEndings.rb > > > On: x86_64-linux > > > ------------------------- > > > Wrote: "abc\ndef\r\nghi\n\rmpq\rrst" > > > Read: "abc\ndef\r\nghi\n\rmpq\rrst" > > > Exp: "abc\ndef\nghi\n\rmpq\rrst" > > > > > > This matches the Java results for you on win32 and for me on > linux.> > I would > > > expect other Linux versions to act the same. > > > > > > So it would appear that Ruby only normalizes \r\n to \n on read on > > > win32platforms, yes? > > > > > > On 6/25/06, Ola Bini <[EMAIL PROTECTED]> wrote: > > > > > > > > > > > > Hi, I've attached a test case for everyone to try out. When I > run> > it,> first with C Ruby, then JRuby HEAD, I get this: > > > > > > > > D:\Project\jruby-fn>ruby testLineEndings.rb > > > > On: i386-mswin32 > > > > ------------------------- > > > > Wrote: "abc\ndef\r\nghi\n\rmpq\rrst" > > > > Read: "abc\ndef\nghi\n\rmpq\rrst" > > > > Exp: "abc\ndef\nghi\n\rmpq\rrst" > > > > > > > > D:\Project\jruby-fn>jruby testLineEndings.rb > > > > On: java > > > > ------------------------- > > > > Wrote: "abc\ndef\r\nghi\n\rmpq\rrst" > > > > Read: "abc\ndef\r\nghi\n\rmpq\rrst" > > > > Exp: "abc\ndef\nghi\n\rmpq\rrst" > > > > > > > > Btw, here you can see another point: my RUBY_PLATFORM isn't > exactly> > > win32 at all, rather it's more than that. Probably > speaks well > > > for us > > > > having some platform string like Java-win32 etc? > > > > > > > > /O > > > > > > > > > > > > > > > > ----- Original Message ----- > > > > From: Charles O Nutter <[EMAIL PROTECTED]> > > > > Date: Sunday, June 25, 2006 7:16 pm > > > > Subject: Re: [Jruby-devel] Newline problem. > > > > To: [EMAIL PROTECTED], jruby-devel@lists.sourceforge.net > > > > > > > > > That would probably be a big help. Tom wasn't able to > reproduce> > the> > issuesyou saw, so if you can put together a > test case that > > > > > demonstrates the > > > > > problem, we'll certainly be able to fix it in the next > release.> > > > > > > > > On 6/24/06, Ola Bini <[EMAIL PROTECTED]> wrote: > > > > > > > > > > > > Hi, > > > > > > > > > > > > Thomas told me my patch for newlines on Win32 didn't really > > > work out > > > > > > that well. I have no problem with it on my box, but if this > > > is a > > > > > stopper> that we want resolved for 0.9, I could write a > small test > > > > > case for > > > > > > people to try out on their respective C and J Ruby's? > > > > > > > > > > > > /O > > > > > > > > > > > > Using Tomcat but need to do more? Need to support web > services,> > > > security?> Get stuff done quickly with pre-integrated > > > technology to > > > > > make your job > > > > > > easier > > > > > > Download IBM WebSphere Application Server v.1.0.1 based on > > > Apache> > Geronimo> http://sel.as- > > > > > us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642> > > > > > _______________________________________________> Jruby-devel > > > > > mailing list > > > > > > Jruby-devel@lists.sourceforge.net > > > > > > https://lists.sourceforge.net/lists/listinfo/jruby-devel > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > Charles Oliver Nutter @ headius.blogspot.com > > > > > JRuby Developer @ jruby.sourceforge.net > > > > > Application Architect @ www.ventera.com > > > > > > > > > > > > > > > > > Using Tomcat but need to do more? Need to support web services, > > > security?> Get stuff done quickly with pre-integrated > technology to > > > make your job > > > > easier > > > > Download IBM WebSphere Application Server v.1.0.1 based on > Apache> > Geronimo> http://sel.as- > > > us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642> > > > > > > > > _______________________________________________ > > > > Jruby-devel mailing list > > > > Jruby-devel@lists.sourceforge.net > > > > https://lists.sourceforge.net/lists/listinfo/jruby-devel > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > Charles Oliver Nutter @ headius.blogspot.com > > > JRuby Developer @ www.jruby.org > > > Application Architect @ www.ventera.com > > > > > > > Using Tomcat but need to do more? Need to support web services, > security?> Get stuff done quickly with pre-integrated technology to > make your job > > easier > > Download IBM WebSphere Application Server v.1.0.1 based on Apache > Geronimo> http://sel.as- > us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642> > _______________________________________________> Jruby-devel > mailing list > > Jruby-devel@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/jruby-devel > > > > > > -- > Charles Oliver Nutter @ headius.blogspot.com > JRuby Developer @ www.jruby.org > Application Architect @ www.ventera.com > Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Jruby-devel mailing list Jruby-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jruby-devel