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

Open
julieqiu opened this issue Jul 20, 2020 · 3 comments
Open

Comments

@julieqiu
Copy link
Contributor

@julieqiu julieqiu commented Jul 20, 2020

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:

@vikramcse
Copy link

@vikramcse vikramcse commented Jul 25, 2020

@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
Contributor Author

@julieqiu julieqiu commented Jul 29, 2020

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

@vikramcse vikramcse commented Aug 4, 2020

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.