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

"Validate the string in context" takes any value and calls "Get Trusted Type compliant string" which requires a TrustedType or a string #488

Closed
mbrodesser-Igalia opened this issue Mar 21, 2024 · 12 comments
Milestone

Comments

@mbrodesser-Igalia
Copy link
Collaborator Author

Alternatively, perhaps https://w3c.github.io/trusted-types/dist/spec/#html-validate-the-string-in-context could be adapted to take either a TrustedType or a string. Then whatwg/webidl#1392 would require adaptation too.

CC @lukewarlow since it might affect above PR.

@mbrodesser-Igalia mbrodesser-Igalia added this to the v1 milestone Mar 25, 2024
@mbrodesser-Igalia
Copy link
Collaborator Author

Tried to learn from an existing spec: https://dom.spec.whatwg.org/#dom-node-textcontent takes a value and calls https://dom.spec.whatwg.org/#string-replace-all which expects a string. However, the stringification of value to string is not specified. Did I miss anything?

CC @domenic

@lukewarlow
Copy link
Member

Yeah you're right the "html" algorithm probably needs updating. I'm not sure what the correct way to do it is though.

@annevk
Copy link
Member

annevk commented Mar 25, 2024

(For textContent stringification follows from IDL and it only accepting a string.)

@lukewarlow
Copy link
Member

That makes sense, and because this is before full type conversion it's just a raw value so we should be handling it.

@mbrodesser-Igalia
Copy link
Collaborator Author

(For textContent stringification follows from IDL and it only accepting a string.)

Why does it follow from IDL? See e.g. https://jsfiddle.net/jmfdasgp/.

@lukewarlow
Copy link
Member

Because the IDL says it's a nullable DOMString so by the time the setter steps are running the value is already either null or stringified.

@mbrodesser-Igalia
Copy link
Collaborator Author

Because the IDL says it's a nullable DOMString so by the time the setter steps are running the value is already either null or stringified.

Agreed.

Where is the conversion from other objects, e.g. from a div element (e.g. https://jsfiddle.net/jmfdasgp/), to a DOMString specified? The IDL for the div element, https://html.spec.whatwg.org/#the-div-element, contains no stringifier and neither do its ancestors.

@lukewarlow
Copy link
Member

contains no stringifier and neither do its ancestors.

The Object type itself has its own stringifier which is what is being used.

@lukewarlow
Copy link
Member

I'm thinking to solve this we could change Get trusted type compliant string to take any type, and then after step 1 insert a new step that stringifies the value (and throws if it can't stringify, I'm not sure any JS type can't be stringified though?)

lukewarlow added a commit to lukewarlow/trusted-types that referenced this issue Apr 4, 2024
… context

Get TT compliant string now takes any value, rather than just string or a TT. It then correctly stringifies this value.

Fixes w3c#488
lukewarlow added a commit to lukewarlow/trusted-types that referenced this issue Apr 4, 2024
… context

Get TT compliant string now takes any value, rather than just string or a TT. It then correctly stringifies this value.

Fixes w3c#488
@petervanderbeken
Copy link

Can this be closed? We're going to be using unions (like DOMString or Trusted*), right? So WebIDL argument conversion will pass either a WebIDL DOMString value or a platform object that implements the right Trusted* type.

@lukewarlow
Copy link
Member

Yep you're right. I'll close this out. (The algorithm will be removed by a draft PR I have)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants