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/pkgsite: responseText links in internal/frontend/fetch.go should be clickable #40306

Closed
julieqiu opened this issue Jul 20, 2020 · 4 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. pkgsite

Comments

@julieqiu
Copy link
Member

When frontend /fetch endpoint returns a response with a status 303 or 404-(but see module page), there are links in the response text that would ideally be clickable. See:

@julieqiu julieqiu added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. pkgsite labels Jul 20, 2020
@gopherbot gopherbot added this to the Unreleased milestone Jul 20, 2020
@vikramcse
Copy link

@julieqiu Before moving ahead, I want to conform about the responseText messages with clickable links
for https://github.com/golang/pkgsite/blob/master/internal/frontend/fetch.go#L208 the responseText would be

Package github.com/module/pkg-nonexistent could not be found, but you can view module “github.com/module” at <a href="https://pkg.go.dev/mod/github.com/module" target="_blank">https://pkg.go.dev/mod/github.com/module</a>.

and for https://github.com/golang/pkgsite/blob/master/internal/frontend/fetch.go#L190 responseText would be

<a href="https://pkg.go.dev/mod/github.com/valid/module_name/foo@v1.0.0" target="_blank">github.com/valid/module_name/foo@v1.0.0</a> is not a valid path.

shall I go ahead with these responseText messages? some guidelines would be helpful :)

@julieqiu
Copy link
Member Author

Please do, thanks @vikramcse! Some minor tweaks:

https://github.com/golang/pkgsite/blob/a956e7c37d48f27cd948f10ab6da5cfaff09302c/internal/frontend/fetch.go#L231

github.com/notvalid/module_name/foo@v1.0.0 is not a valid path. Were you looking for "<a href="https://pkg.go.dev/mod/github.com/valid/module_name/foo@v1.0.0" target="_blank">github.com/valid/module_name/foo@v1.0.0</a>"?

https://github.com/golang/pkgsite/blob/a956e7c37d48f27cd948f10ab6da5cfaff09302c/internal/frontend/fetch.go#L250

Package github.com/module/pkg-nonexistent could not be found, but you can view module “github.com/module” at <a href="https://pkg.go.dev/mod/github.com/module" target="_blank">pkg.go.dev/mod/github.com/module</a>.

@vikramcse
Copy link

Hi @julieqiu
I am able to run the frontend server and able to reproduce the above case.

responseText contains text with html containt (anchor tag)

below code snippet from https://github.com/golang/pkgsite/blob/master/internal/frontend/details.go#L502 which renders the errors

epage: &errorPage{
	messageTemplate: template.MakeTrustedTemplate(`
		<h3 class="Error-message">{{.StatusText}}</h3>
		<p class="Error-message">{{.Response}}</p>`),
	MessageData: struct{ StatusText, Response string }{http.StatusText(status), responseText},
}

I tried looking into the documentation of package https://github.com/google/safehtml to convert responseText into HTML
but could not find the proper method.

I also tried template.MustParseAndExecuteToHTML() which will give parsed html, but this method accepts untyped string stringConstant which is unexported.

what could be the proper method the parse above text?

@gopherbot
Copy link

Change https://golang.org/cl/277117 mentions this issue: internal/frontend: Make links on 404 => Request page clickable

@golang golang locked and limited conversation to collaborators Dec 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. pkgsite
Projects
None yet
Development

No branches or pull requests

3 participants