Skip to content

x/website: unable to use custom path without trailing slash ("/") in an HTML file, if it is named index.html #40665

@stevetraut

Description

@stevetraut

What version of Go are you using (go version)?

% go version
go version go1.14.7 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
% go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/straut/Library/Caches/go-build"
GOENV="/Users/straut/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/straut/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/9m/40r8ccc13c53mcyc85qzjmd400d81r/T/go-build148293827=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

  1. In website/content/static/doc/, add an index.html with the following content.
    <!--{
    "Title": "Documentation",
    "Path": "/doc/"
    }-->
    
    <p>This is the index file.</p>
    
  2. In website/content/static/internal/gen/gen.go, add the following entry to var files = []string{ ... }:
    var files = []string{
        ...
        "doc/index.html",
        ...
    }
    
  3. Open website/content/static/doc/docs.html, and change the header to the following (to avoid a path collision):
    <!--{
    "Title": "Documentation",
    "Path": "/doc/docs",
    "Template": true
    }-->
    
  4. cd to the website/ directory
    cd my-repo/website
    
  5. Generate the website.
    go generate golang.org/x/website/content/static
    
  6. Run the site.
    go run golang.org/x/website/cmd/golangorg -http=:6060
    
  7. In a browser, visit the page you just created:
    http://localhost:6060/doc/
    
  8. In the console, note three errors ending with the following:
    2020/08/10 09:20:14 http: panic serving [::1]:55541: runtime error: slice bounds out of range [:-5]
    goroutine 1138 [running]:
    net/http.(*conn).serve.func1(0xc0001443c0)
        /usr/local/go/src/net/http/server.go:1800 +0x139
    panic(0x176f6c0, 0xc0006e29c0)
        /usr/local/go/src/runtime/panic.go:975 +0x3e3
    golang.org/x/tools/godoc.(*Presentation).serveFile(0xc0002f8000, 0x1a24aa0, 0xc0001da460, 0xc0003ca400)
        /Users/straut/go/pkg/mod/golang.org/x/tools@v0.0.0-20200617212913-87be026d3888/godoc/server.go:778 +0x87d
    golang.org/x/tools/godoc.(*Presentation).ServeFile(...)
        /Users/straut/go/pkg/mod/golang.org/x/tools@v0.0.0-20200617212913-87be026d3888/godoc/server.go:753
    net/http.HandlerFunc.ServeHTTP(0xc00031a480, 0x1a24aa0, 0xc0001da460, 0xc0003ca400)
        /usr/local/go/src/net/http/server.go:2041 +0x44
    net/http.(*ServeMux).ServeHTTP(0xc000fbc080, 0x1a24aa0, 0xc0001da460, 0xc0003ca400)
        /usr/local/go/src/net/http/server.go:2416 +0x1a5
    golang.org/x/tools/godoc.(*Presentation).ServeHTTP(0xc0002f8000, 0x1a24aa0, 0xc0001da460, 0xc0003ca400)
        /Users/straut/go/pkg/mod/golang.org/x/tools@v0.0.0-20200617212913-87be026d3888/godoc/pres.go:143 +0x4d
    net/http.(*ServeMux).ServeHTTP(0xc000b70540, 0x1a24aa0, 0xc0001da460, 0xc0003ca400)
        /usr/local/go/src/net/http/server.go:2416 +0x1a5
    main.hostEnforcerHandler.ServeHTTP(0x1a18b20, 0xc000b70540, 0x1a24aa0, 0xc0001da460, 0xc0003ca400)
        /Users/straut/Documents/workfiles/go/repo/git/website/cmd/golangorg/handlers.go:45 +0x380
    net/http.(*ServeMux).ServeHTTP(0x1e9e580, 0x1a24aa0, 0xc0001da460, 0xc0003ca400)
        /usr/local/go/src/net/http/server.go:2416 +0x1a5
    net/http.serverHandler.ServeHTTP(0xc0001da2a0, 0x1a24aa0, 0xc0001da460, 0xc0003ca400)
        /usr/local/go/src/net/http/server.go:2836 +0xa3
    net/http.(*conn).serve(0xc0001443c0, 0x1a25e20, 0xc000fbc280)
        /usr/local/go/src/net/http/server.go:1924 +0x86c
    created by net/http.(*Server).Serve
        /usr/local/go/src/net/http/server.go:2962 +0x35c
    

What did you expect to see?

The index page I created loads when I visit the directory in a browser.

What did you see instead?

The panic above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions