LGTM On Wed, Feb 22, 2012 at 5:43 PM, <gri@golang.org> wrote: > Reviewers: golang-dev_googlegroups.com, > ...
13 years, 3 months ago
(2012-02-22 06:47:24 UTC)
#2
LGTM
On Wed, Feb 22, 2012 at 5:43 PM, <gri@golang.org> wrote:
> Reviewers: golang-dev_googlegroups.com,
>
> Message:
> Hello golang-dev@googlegroups.com,
>
> I'd like you to review this change to
> https://go.googlecode.com/hg/
>
>
> Description:
> godoc: fix potential index out-of-bounds error
>
> Please review this at
http://codereview.appspot.com/**5683072/<http://codereview.appspot.com/5683072/>
>
> Affected files:
> M src/cmd/godoc/mapping.go
>
>
> Index: src/cmd/godoc/mapping.go
> ==============================**==============================**=======
> --- a/src/cmd/godoc/mapping.go
> +++ b/src/cmd/godoc/mapping.go
> @@ -139,6 +139,8 @@
> }
> }
>
> +const sep = string(filepath.Separator)
> +
> // splitFirst splits a path at the first path separator and returns
> // the path's head (the top-most directory specified by the path) and
> // its tail (the rest of the path). If there is no path separator,
> @@ -146,7 +148,7 @@
> // Specifically, splitFirst("foo") == splitFirst("foo/").
> //
> func splitFirst(path string) (head, tail string) {
> - if i := strings.Index(path, string(filepath.Separator)); i > 0 {
> + if i := strings.Index(path, sep); i > 0 {
> // 0 < i < len(path)
> return path[0:i], path[i+1:]
> }
> @@ -179,7 +181,7 @@
> func (m *Mapping) ToRelative(fpath string) string {
> for _, e := range m.list {
> // if fpath has prefix e.path, the next character must be a
> separator (was issue 3096)
> - if strings.HasPrefix(fpath, e.path) && fpath[len(e.path)]
> == filepath.Separator {
> + if strings.HasPrefix(fpath, e.path+sep) {
> spath := filepath.ToSlash(fpath)
> // /absolute/prefix/foo -> prefix/foo
> return path.Join(e.prefix, spath[len(e.path):]) //
> Join will remove a trailing '/'
>
>
>
Issue 5683072: code review 5683072: godoc: fix potential index out-of-bounds error
(Closed)
Created 13 years, 3 months ago by gri
Modified 13 years, 3 months ago
Reviewers:
Base URL:
Comments: 0