You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Randy Kobes <ra...@theoryx5.uwinnipeg.ca> on 2004/07/01 06:59:42 UTC

[mp2] api/sendfile.t on Win32

On Win32, the first subtest of api/sendfile.t fails
due to different line endings. This diff:
====================================================
Index: t/api/sendfile.t
===================================================================
RCS file: /home/cvs/modperl-2.0/t/api/sendfile.t,v
retrieving revision 1.7
diff -u -r1.7 sendfile.t
--- t/api/sendfile.t	29 Jun 2004 22:56:16 -0000	1.7
+++ t/api/sendfile.t	1 Jul 2004 04:43:55 -0000
@@ -4,6 +4,7 @@
 use Apache::Test;
 use Apache::TestUtil;
 use Apache::TestRequest;
+use Apache::TestConfig ();

 use File::Spec::Functions qw(catfile);

@@ -24,6 +25,7 @@
     close $fh;

     my $received = GET_BODY($url);
+    $received =~ s{\r}{}g if Apache::TestConfig::WIN32;

     t_debug($received);
     ok $received && $received eq $expected;

==================================================================
fixes it.

-- 
best regards,
randy

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2] api/sendfile.t on Win32

Posted by Stas Bekman <st...@stason.org>.
Randy Kobes wrote:
> On Thu, 1 Jul 2004, Stas Bekman wrote:
> 
> 
>>Randy Kobes wrote:
>>
>>
>>>Another way to get the test as written
>>>to pass is is to open the file in binary mode:
>>
>>I'm now not sure what's going on win32, <fh> removes \r
>>but sendfile not?
> 
> 
> That's right - if you open a text file on Win32 without
> binmode, the \r are removed, and if binmode is used,
> they stay.

Thanks for the explanation, Randy.


-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2] api/sendfile.t on Win32

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Thu, 1 Jul 2004, Stas Bekman wrote:

> Randy Kobes wrote:
>
> > Another way to get the test as written
> > to pass is is to open the file in binary mode:
>
> I'm now not sure what's going on win32, <fh> removes \r
> but sendfile not?

That's right - if you open a text file on Win32 without
binmode, the \r are removed, and if binmode is used,
they stay.

[ ... ]
> Adding a short comment why we use binmode should be good
> enough I believe. Go ahead and commit that patch
> (+comment). Thanks Randy.

Thanks - I'll do that.

-- 
best regards,
randy

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2] api/sendfile.t on Win32

Posted by Stas Bekman <st...@stason.org>.
Randy Kobes wrote:
> On Wed, 30 Jun 2004, Stas Bekman wrote:
> 
> 
>>Randy Kobes wrote:
>>
>>>On Wed, 30 Jun 2004, Stas Bekman wrote:
>>>
>>>
>>>
>>>>Randy Kobes wrote:
>>>>
>>>>
>>>>>On Win32, the first subtest of api/sendfile.t fails
>>>>>due to different line endings. This diff:
>>
>>[...]
>>
>>>>>    my $received = GET_BODY($url);
>>>>>+    $received =~ s{\r}{}g if Apache::TestConfig::WIN32;
>>
>>[...]
>>
>>>>>==================================================================
>>>>>fixes it.
>>>>
>>>>How about a fix without win32 branching -- just drop "\n"
>>>>on both sides? Or is it the one coming from a file that is
>>>>sendfile'd?
>>>
>>>It's that coming from the file being sendfile'd. And I guess
>>>we shouldn't alter with what sendfile produces?
>>
>>Hmm, is that correct at all? why would it stuff \r into a
>>file that didn't have it? Or does it do that only for text
>>files (assuming it somehow figures out it's not a binary
>>file). What if you send an image file, does it stuff \r
>>there too if it finds \n?
> 
> 
> Maybe I didn't understand the original comment ... But I
> tried sending a png file, and they compared as equal without
> the \r substitution. 

May be there weren't any \n lines in it?

> Another way to get the test as written
> to pass is is to open the file in binary mode:

I'm now not sure what's going on win32, <fh> removes \r but sendfile not?

> ===========================================================
> Index: t/api/sendfile.t
> ===================================================================
> RCS file: /home/cvs/modperl-2.0/t/api/sendfile.t,v
> retrieving revision 1.7
> diff -u -r1.7 sendfile.t
> --- t/api/sendfile.t	29 Jun 2004 22:56:16 -0000	1.7
> +++ t/api/sendfile.t	1 Jul 2004 06:16:46 -0000
> @@ -20,6 +20,7 @@
> 
>      open my $fh, $file or die "can't open $file: $!";
>      local $/;
> +    binmode $fh;
>      my $expected = join '', $header, <$fh>, $footer;
>      close $fh;
> 
> =============================================================
> This should be OK on unix too, but is a little unintuitive
> to a casual reader - unix people wouldn't open a simple text
> file like this in binary mode, as there's no reason, and
> Win32 people don't want to open a text file in binary mode,
> unless they want the \r line endings.
> 
> It sounds like then that sendfile sends either a text or
> binary file in binary mode, without doing a \r translation.

Adding a short comment why we use binmode should be good enough I believe. Go 
ahead and commit that patch (+comment). Thanks Randy.




-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2] api/sendfile.t on Win32

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Wed, 30 Jun 2004, Stas Bekman wrote:

> Randy Kobes wrote:
> > On Wed, 30 Jun 2004, Stas Bekman wrote:
> >
> >
> >>Randy Kobes wrote:
> >>
> >>>On Win32, the first subtest of api/sendfile.t fails
> >>>due to different line endings. This diff:
> [...]
> >>>     my $received = GET_BODY($url);
> >>>+    $received =~ s{\r}{}g if Apache::TestConfig::WIN32;
> [...]
> >>>==================================================================
> >>>fixes it.
> >>
> >>How about a fix without win32 branching -- just drop "\n"
> >>on both sides? Or is it the one coming from a file that is
> >>sendfile'd?
> >
> > It's that coming from the file being sendfile'd. And I guess
> > we shouldn't alter with what sendfile produces?
>
> Hmm, is that correct at all? why would it stuff \r into a
> file that didn't have it? Or does it do that only for text
> files (assuming it somehow figures out it's not a binary
> file). What if you send an image file, does it stuff \r
> there too if it finds \n?

Maybe I didn't understand the original comment ... But I
tried sending a png file, and they compared as equal without
the \r substitution. Another way to get the test as written
to pass is is to open the file in binary mode:
===========================================================
Index: t/api/sendfile.t
===================================================================
RCS file: /home/cvs/modperl-2.0/t/api/sendfile.t,v
retrieving revision 1.7
diff -u -r1.7 sendfile.t
--- t/api/sendfile.t	29 Jun 2004 22:56:16 -0000	1.7
+++ t/api/sendfile.t	1 Jul 2004 06:16:46 -0000
@@ -20,6 +20,7 @@

     open my $fh, $file or die "can't open $file: $!";
     local $/;
+    binmode $fh;
     my $expected = join '', $header, <$fh>, $footer;
     close $fh;

=============================================================
This should be OK on unix too, but is a little unintuitive
to a casual reader - unix people wouldn't open a simple text
file like this in binary mode, as there's no reason, and
Win32 people don't want to open a text file in binary mode,
unless they want the \r line endings.

It sounds like then that sendfile sends either a text or
binary file in binary mode, without doing a \r translation.

-- 
best regards,
randy

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2] api/sendfile.t on Win32

Posted by Stas Bekman <st...@stason.org>.
Randy Kobes wrote:
> On Wed, 30 Jun 2004, Stas Bekman wrote:
> 
> 
>>Randy Kobes wrote:
>>
>>>On Win32, the first subtest of api/sendfile.t fails
>>>due to different line endings. This diff:
[...]
>>>     my $received = GET_BODY($url);
>>>+    $received =~ s{\r}{}g if Apache::TestConfig::WIN32;
[...]
>>>==================================================================
>>>fixes it.
>>
>>How about a fix without win32 branching -- just drop "\n"
>>on both sides? Or is it the one coming from a file that is
>>sendfile'd?
> 
> 
> It's that coming from the file being sendfile'd. And I guess
> we shouldn't alter with what sendfile produces?

Hmm, is that correct at all? why would it stuff \r into a file that didn't 
have it? Or does it do that only for text files (assuming it somehow figures 
out it's not a binary file). What if you send an image file, does it stuff \r 
there too if it finds \n?


-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2] api/sendfile.t on Win32

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Wed, 30 Jun 2004, Stas Bekman wrote:

> Randy Kobes wrote:
> > On Win32, the first subtest of api/sendfile.t fails
> > due to different line endings. This diff:
> > ====================================================
> > Index: t/api/sendfile.t
> > ===================================================================
> > RCS file: /home/cvs/modperl-2.0/t/api/sendfile.t,v
> > retrieving revision 1.7
> > diff -u -r1.7 sendfile.t
> > --- t/api/sendfile.t	29 Jun 2004 22:56:16 -0000	1.7
> > +++ t/api/sendfile.t	1 Jul 2004 04:43:55 -0000
> > @@ -4,6 +4,7 @@
> >  use Apache::Test;
> >  use Apache::TestUtil;
> >  use Apache::TestRequest;
> > +use Apache::TestConfig ();
> >
> >  use File::Spec::Functions qw(catfile);
> >
> > @@ -24,6 +25,7 @@
> >      close $fh;
> >
> >      my $received = GET_BODY($url);
> > +    $received =~ s{\r}{}g if Apache::TestConfig::WIN32;
> >
> >      t_debug($received);
> >      ok $received && $received eq $expected;
> >
> > ==================================================================
> > fixes it.
>
> How about a fix without win32 branching -- just drop "\n"
> on both sides? Or is it the one coming from a file that is
> sendfile'd?

It's that coming from the file being sendfile'd. And I guess
we shouldn't alter with what sendfile produces?

-- 
best regards,
randy

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2] api/sendfile.t on Win32

Posted by Stas Bekman <st...@stason.org>.
Randy Kobes wrote:
> On Win32, the first subtest of api/sendfile.t fails
> due to different line endings. This diff:
> ====================================================
> Index: t/api/sendfile.t
> ===================================================================
> RCS file: /home/cvs/modperl-2.0/t/api/sendfile.t,v
> retrieving revision 1.7
> diff -u -r1.7 sendfile.t
> --- t/api/sendfile.t	29 Jun 2004 22:56:16 -0000	1.7
> +++ t/api/sendfile.t	1 Jul 2004 04:43:55 -0000
> @@ -4,6 +4,7 @@
>  use Apache::Test;
>  use Apache::TestUtil;
>  use Apache::TestRequest;
> +use Apache::TestConfig ();
> 
>  use File::Spec::Functions qw(catfile);
> 
> @@ -24,6 +25,7 @@
>      close $fh;
> 
>      my $received = GET_BODY($url);
> +    $received =~ s{\r}{}g if Apache::TestConfig::WIN32;
> 
>      t_debug($received);
>      ok $received && $received eq $expected;
> 
> ==================================================================
> fixes it.

How about a fix without win32 branching -- just drop "\n" on both sides? Or is 
it the one coming from a file that is sendfile'd?


-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org