code review 7225070: cmd/godoc: fix buggy use of strings.HasSuffix (issue 7225070)

34 views
Skip to first unread message

brad...@golang.org

unread,
Jan 30, 2013, 2:46:03 PM1/30/13
to golan...@googlegroups.com, re...@codereview-hr.appspotmail.com
Reviewers: golang-dev_googlegroups.com,

Message:
Hello golan...@googlegroups.com,

I'd like you to review this change to
https://go.googlecode.com/hg/


Description:
cmd/godoc: fix buggy use of strings.HasSuffix

This code never worked. Maybe it's not necessary?

Please review this at https://codereview.appspot.com/7225070/

Affected files:
M src/cmd/godoc/godoc.go


Index: src/cmd/godoc/godoc.go
===================================================================
--- a/src/cmd/godoc/godoc.go
+++ b/src/cmd/godoc/godoc.go
@@ -652,7 +652,7 @@

func redirect(w http.ResponseWriter, r *http.Request) (redirected bool) {
canonical := pathpkg.Clean(r.URL.Path)
- if !strings.HasSuffix("/", canonical) {
+ if !strings.HasSuffix(canonical, "/") {
canonical += "/"
}
if r.URL.Path != canonical {
@@ -666,9 +666,7 @@

func redirectFile(w http.ResponseWriter, r *http.Request) (redirected
bool) {
c := pathpkg.Clean(r.URL.Path)
- for strings.HasSuffix("/", c) {
- c = c[:len(c)-1]
- }
+ c = strings.TrimRight(c, "/")
if r.URL.Path != c {
url := *r.URL
url.Path = c


Russ Cox

unread,
Jan 30, 2013, 2:52:07 PM1/30/13
to Brad Fitzpatrick, golang-dev, re...@codereview-hr.appspotmail.com
LGTM

The code is necessary, it's just broken.
golang.org seems to be working correctly but tip.golang.org is not.

For example:

brad...@golang.org

unread,
Jan 30, 2013, 3:30:49 PM1/30/13
to brad...@golang.org, golan...@googlegroups.com, r...@golang.org, re...@codereview-hr.appspotmail.com
*** Submitted as
https://code.google.com/p/go/source/detail?r=59521f9a2f0f ***

cmd/godoc: fix buggy use of strings.HasSuffix

This code never worked. Maybe it's not necessary?

R=golang-dev, rsc
CC=golang-dev
https://codereview.appspot.com/7225070


https://codereview.appspot.com/7225070/
Reply all
Reply to author
Forward
0 new messages