Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
stevetraut opened this issue Aug 10, 2020 · 3 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@stevetraut
Copy link

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.

@gopherbot gopherbot added this to the Unreleased milestone Aug 10, 2020
@andybons andybons added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 10, 2020
@andybons
Copy link
Member

@dmitshur

@andybons andybons changed the title x/website: Unable to use index.html file as default for website directory. x/website: unable to use index.html file as default for website directory. Aug 10, 2020
@dmitshur dmitshur self-assigned this Aug 10, 2020
@dmitshur dmitshur changed the title x/website: unable to use index.html file as default for website directory. x/website: unable to use custom path without trailing slash ("/") in an HTML file, if it is named index.html Aug 10, 2020
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Aug 10, 2020
@gopherbot
Copy link

Change https://golang.org/cl/251080 mentions this issue: godoc: fix panic in Presentation.ServeFile

gopherbot pushed a commit to golang/tools that referenced this issue Aug 27, 2020
The redirect to drop index.html must be done using r.URL.Path,
not relpath, because those might differ. Cutting len("index.html")
bytes off a string that doesn't end in index.html is incorrect.

While we're here, silence an annoying log print during go test.

For golang/go#40665.

Change-Id: I36553b041f53eab9c42da6b77184e90800a97e92
Reviewed-on: https://go-review.googlesource.com/c/tools/+/251080
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
@dmitshur dmitshur removed their assignment Aug 27, 2020
@gopherbot
Copy link

Change https://golang.org/cl/251118 mentions this issue: website: update to tools@97606e32

@golang golang locked and limited conversation to collaborators Aug 27, 2021
passionSeven added a commit to passionSeven/website that referenced this issue Oct 18, 2022
The other changes in go.mod and go.sum are implied by the updated tools.

Fixes golang/go#40665.

Change-Id: I874c839d64c7cec21a40278bb47b5f686d766f99
Reviewed-on: https://go-review.googlesource.com/c/website/+/251118
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants