Skip to content

Commit

Permalink
fix tests that rely on net/http package appending "\n" to redirect …
Browse files Browse the repository at this point in the history
…link

PiperOrigin-RevId: 621504517
Change-Id: I36588c00c3c8cff48953d6ca4cf4551c9ae14516
  • Loading branch information
Google Cloud Healthcare Team authored and copybara-github committed Apr 3, 2024
1 parent e7e585c commit d987db8
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 27 deletions.
2 changes: 1 addition & 1 deletion lib/httputils/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func WriteCorsHeaders(w http.ResponseWriter) {
// RedirectHTMLPage retuns the HTML page generated by http.Redirect.
// This is copied from http package.
func RedirectHTMLPage(dst string) string {
return `<a href="` + HTMLReplacer.Replace(dst) + `">See Other</a>.` + "\n"
return `<a href="` + HTMLReplacer.Replace(dst) + `">See Other</a>.` + "\n\n"
}

// HTMLReplacer escape URL parameters for HTML.
Expand Down
26 changes: 0 additions & 26 deletions lib/httputils/handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package httputils
import (
"net/http"
"net/url"
"strings"
"testing"

"github.com/google/go-cmp/cmp" /* copybara-comment */
Expand Down Expand Up @@ -194,11 +193,6 @@ func TestWriteRedirect(t *testing.T) {
Body: RedirectHTMLPage(dst),
Code: http.StatusSeeOther,
}
// TODO: remove this workaround after we submit new Go toolchain (b/324535216) to google3.
// https://go.dev/cl/562356 removes superfluous newline on redirects and makes this test fail.
// Remove all '\n' symbols from both string before comparing.
want.Body = strings.ReplaceAll(want.Body, "\n", "")
w.Body = strings.ReplaceAll(w.Body, "\n", "")
if diff := cmp.Diff(want, w); diff != "" {
t.Errorf("WriteRedirect(); Writer diff (-want +got):\n%s", diff)
}
Expand Down Expand Up @@ -232,11 +226,6 @@ func TestWriteRedirect_ParsedDestination(t *testing.T) {
Body: RedirectHTMLPage(dst),
Code: http.StatusSeeOther,
}
// TODO: remove this workaround after we submit new Go toolchain (b/324535216) to google3.
// https://go.dev/cl/562356 removes superfluous newline on redirects and makes this test fail.
// Remove all '\n' symbols from both string before comparing.
want.Body = strings.ReplaceAll(want.Body, "\n", "")
w.Body = strings.ReplaceAll(w.Body, "\n", "")
if diff := cmp.Diff(want, w); diff != "" {
t.Errorf("WriteRedirect(); Writer diff (-want +got):\n%s", diff)
}
Expand Down Expand Up @@ -265,11 +254,6 @@ func TestWriteRedirect_RelativeDestination(t *testing.T) {
Body: RedirectHTMLPage("/srcresources/" + dst),
Code: http.StatusSeeOther,
}
// TODO: remove this workaround after we submit new Go toolchain (b/324535216) to google3.
// https://go.dev/cl/562356 removes superfluous newline on redirects and makes this test fail.
// Remove all '\n' symbols from both string before comparing.
want.Body = strings.ReplaceAll(want.Body, "\n", "")
w.Body = strings.ReplaceAll(w.Body, "\n", "")
if diff := cmp.Diff(want, w); diff != "" {
t.Errorf("WriteRedirect(); Writer diff (-want +got):\n%s", diff)
}
Expand Down Expand Up @@ -298,11 +282,6 @@ func TestWriteRedirect_RelativeDestinationAtRoot(t *testing.T) {
Body: RedirectHTMLPage(dst),
Code: http.StatusSeeOther,
}
// TODO: remove this workaround after we submit new Go toolchain (b/324535216) to google3.
// https://go.dev/cl/562356 removes superfluous newline on redirects and makes this test fail.
// Remove all '\n' symbols from both string before comparing.
want.Body = strings.ReplaceAll(want.Body, "\n", "")
w.Body = strings.ReplaceAll(w.Body, "\n", "")
if diff := cmp.Diff(want, w); diff != "" {
t.Errorf("WriteRedirect(); Writer diff (-want +got):\n%s", diff)
}
Expand Down Expand Up @@ -350,11 +329,6 @@ func TestWriteRedirect_FullyEncodedRedirectURLParameter(t *testing.T) {
Body: RedirectHTMLPage(dst),
Code: http.StatusSeeOther,
}
// TODO: remove this workaround after we submit new Go toolchain (b/324535216) to google3.
// https://go.dev/cl/562356 removes superfluous newline on redirects and makes this test fail.
// Remove all '\n' symbols from both string before comparing.
want.Body = strings.ReplaceAll(want.Body, "\n", "")
w.Body = strings.ReplaceAll(w.Body, "\n", "")
if diff := cmp.Diff(want, w); diff != "" {
t.Errorf("WriteRedirect(); Writer diff (-want +got):\n%s", diff)
}
Expand Down

0 comments on commit d987db8

Please sign in to comment.