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

html/template: "application/ld+json" MIME type is not understood as JS #26053

Open
eklitzke opened this Issue Jun 25, 2018 · 3 comments

Comments

Projects
None yet
4 participants
@eklitzke

eklitzke commented Jun 25, 2018

The text/html package does not understand the "application/ld+json" MIME type to be JS. This is a standard format endorsed by the W3C and various search engines. Search engines like Google require this data to be inline in a page's HTML using a tag like <script type="application/ld+json">JSON DATA HERE</script>, so it is important for the text/html template engine to be aware of how to escape JSON-LD data, as the data cannot be placed in an external script file. For more information on JSON-LD see [1] and [2].

I plan to submit a trivial PR to add json+ld support to text/html, but I am creating a GitHub issue first to describe the issue as per the contribution policy.

[1] https://en.wikipedia.org/wiki/JSON-LD
[2] https://developers.google.com/search/docs/guides/intro-structured-data

eklitzke added a commit to eklitzke/go that referenced this issue Jun 25, 2018

text/html: MIME type "application/ld+json: should be escaped as JS
This change teaches the text/html package to understand the
"application/ld+json" MIME type (used for JSON-LD data) as Javascript, so it can
be escaped contextually.

Fixes golang#26053

eklitzke added a commit to eklitzke/go that referenced this issue Jun 25, 2018

text/html: MIME type "application/ld+json: should be escaped as JS
Teach the text/html package to understand the "application/ld+json" MIME
type (used for JSON-LD data) as JS, so it can be apply the correct contextual
escaping.

Fixes golang#26053
@gopherbot

This comment has been minimized.

gopherbot commented Jun 25, 2018

Change https://golang.org/cl/120835 mentions this issue: text/html: MIME type "application/ld+json: should be escaped as JS

@bradfitz bradfitz added this to the Go1.12 milestone Jun 25, 2018

@bradfitz

This comment has been minimized.

Member

bradfitz commented Jun 25, 2018

@odeke-em odeke-em changed the title from text/html: "application/ld+json" MIME type is not understood as JS to html/template: "application/ld+json" MIME type is not understood as JS Jun 26, 2018

@FiloSottile

This comment has been minimized.

Member

FiloSottile commented Jun 26, 2018

A JSON-LD document must be a valid JSON document as described in [RFC4627].

For the purposes of text/html, this is indeed JSON. LGTM.

@FiloSottile FiloSottile added NeedsFix and removed NeedsDecision labels Jun 26, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment