t/gitweb-lib: Split HTTP response with non-GNU sed
PATCH 1/1 t/gitweb-lib: Split HTTP response with non-GNU sed
Recognizing \r in a regex is something GNU sed will do, but other sed implementation's won't. (Found with BSD sed on OS X.) So use a literal carriage return instead.
--- t/gitweb-lib.sh | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
t/gitweb-lib.sh +1 -2
@@ -52,8 +52,8 @@ gitweb_run () { rm -f gitweb.log && perl -- "$SCRIPT_NAME" \ >gitweb.output 2>gitweb.log && - sed -e '/^\r$/q' <gitweb.output >gitweb.headers && - sed -e '1,/^\r$/d' <gitweb.output >gitweb.body && + sed -e '/^
$/q' <gitweb.output >gitweb.headers &&
+ sed -e '1,/^
$/d' <gitweb.output >gitweb.body &&
if grep '^[[]' gitweb.log >/dev/null 2>&1; then false; else true; fi
# gitweb.log is left for debugging
Signature · 1 line
1.6.5.3.433.g11067
Quoted 3 lines · Brian Gernhardt
Recognizing \r in a regex is something GNU sed will do, but other sed implementation's won't. (Found with BSD sed on OS X.) So use a literal carriage return instead.
I'd actually prefer not having to deal with this issue. How about doing something like this instead?
t/gitweb-lib.sh | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-)
t/gitweb-lib.sh +12 -2
@@ -52,8 +52,18 @@ gitweb_run () { rm -f gitweb.log && perl -- "$SCRIPT_NAME" \ >gitweb.output 2>gitweb.log && - sed -e '/^\r$/q' <gitweb.output >gitweb.headers && - sed -e '1,/^\r$/d' <gitweb.output >gitweb.body && + perl -w -e ' + open O, ">gitweb.headers"; + while (<>) { + print O; + last if (/^\r$/ || /^$/); + } + open O, ">gitweb.body"; + while (<>) { + print O; + } + close O; + ' gitweb.output && if grep '^[[]' gitweb.log >/dev/null 2>&1; then false; else true; fi # gitweb.log is left for debugging
Quoted 5 lines · Junio C Hamano
Quoted 3 lines · Brian Gernhardt
Recognizing \r in a regex is something GNU sed will do, but other sed implementation's won't. (Found with BSD sed on OS X.) So use a literal carriage return instead.
[...]
Quoted 9 lines
Quoted 9 lines
t/gitweb-lib.sh +0
-0@@ -52,8 +52,8 @@ gitweb_run () {rm -f gitweb.log &&
perl -- "$SCRIPT_NAME" \
>gitweb.output 2>gitweb.log &&
- sed -e '/^\r$/q' <gitweb.output >gitweb.headers &&
Quoted 8 lines
Quoted 8 lines
- sed -e '1,/^\r$/d' <gitweb.output >gitweb.body && + sed -e '/^
$/q' <gitweb.output >gitweb.headers &&
+ sed -e '1,/^
$/d' <gitweb.output >gitweb.body &&
if grep '^[[]' gitweb.log >/dev/null 2>&1; then false; else true; fi# gitweb.log is left for debugging
If we were to do it this way, I would prefer to set and then use 'cr' or 'crlf' variable (in sed expression).
Quoted 12 lines
I'd actually prefer not having to deal with this issue. How about doing something like this instead?
t/gitweb-lib.sh | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-)t/gitweb-lib.sh +0
-0
t/gitweb-lib.sh gitweb_run () { · line 55
Quoted 6 lines
t/gitweb-lib.sh +1
-2@@ -52,8 +52,18 @@ gitweb_run () { rm -f gitweb.log && perl -- "$SCRIPT_NAME" \ >gitweb.output 2>gitweb.log && - sed -e '/^\r$/q' <gitweb.output >gitweb.headers && - sed -e '1,/^\r$/d' <gitweb.output >gitweb.body && + perl -w -e '
"perl", or "$PERL", or "$PERL_PATH"?
t/gitweb-lib.sh gitweb_run () { · line 56
Quoted 1 line
t/gitweb-lib.sh +1
-0+ open O, ">gitweb.headers";
Well, modern Perl would use here
+ open my $fh, ">", "gitweb.headers";
But it is not that important here.
Quoted 4 lines
t/gitweb-lib.sh +3
-0+ while (<>) { + print O; + last if (/^\r$/ || /^$/);
t/gitweb-lib.sh gitweb_run () { · line 69
Quoted 10 lines
t/gitweb-lib.sh +7
-0+ } + open O, ">gitweb.body"; + while (<>) { + print O; + } + close O; + ' gitweb.output && if grep '^[[]' gitweb.log >/dev/null 2>&1; then false; else true; fi # gitweb.log is left for debugging
This is a good solution. We test Perl script anyway (so Perl is required for running this test), and this way we can do this portably and in one pass (one fork).
Signature · 2 lines
Jakub Narebski Poland
Quoted 8 lines · Junio C Hamano
Quoted 3 lines · Brian Gernhardt
Recognizing \r in a regex is something GNU sed will do, but other sed implementation's won't. (Found with BSD sed on OS X.) So use a literal carriage return instead.
I'd actually prefer not having to deal with this issue. How about doing something like this instead?
Works for me. I just went for the obvious minimal change to make it work. But since we're testing a perl script, we might as well just use perl to deal with it's output.
~~ Brian