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

provide clearer advice about USVString vs. DOMString #84

Open
dbaron opened this issue Jan 14, 2016 · 9 comments
Open

provide clearer advice about USVString vs. DOMString #84

dbaron opened this issue Jan 14, 2016 · 9 comments
Labels
☕☕ difficulty:medium Hard to fix ⌛ duration:short Should be a short fix editorial Changes that do not affect how the standard is understood topic: string

Comments

@dbaron
Copy link
Member

dbaron commented Jan 14, 2016

In w3ctag/design-reviews#87 (comment) (see also the following comment) we had a brief discussion about USVString vs. DOMString. This seems like a somewhat tricky (in that it's easy to get wrong) API design issue, and the current wording in WebIDL isn't particularly clear.

http://heycam.github.io/webidl/#idl-USVString currently says:

Specifications SHOULD only use USVString for APIs that perform text processing and need a string of Unicode scalar values to operate on. Most APIs that use strings should instead be using DOMString, which does not make any interpretations of the code units in the string. When in doubt, use DOMString.

This is a bit unclear in a few ways (not clear what "text processing" means; does encoding conversion count?), and doesn't seem to match the other advice being given, e.g., in w3ctag/design-reviews#87 (comment)

This seems like an area where giving clear and consistent advice is important.

@tobie tobie added ⌛ duration:short Should be a short fix editorial Changes that do not affect how the standard is understood ☕☕ difficulty:medium Hard to fix labels Jun 18, 2016
@annevk
Copy link
Member

annevk commented Mar 29, 2017

The plan is to rephrase this in terms of https://infra.spec.whatwg.org/#strings and use JavaScript (for DOMString) and scalar value string (for USVString) from there. Is the difference sufficiently clear there?

@SimonSapin
Copy link

SimonSapin commented Apr 15, 2017

@annevk I think you’re response is about what each of the two types are, while @dbaron’s comment was about why and in what situations is one recommended over the other. I agree that it is unclear where “APIs that perform text processing” applies.

@annevk
Copy link
Member

annevk commented Apr 16, 2017

No, it specifically calls out UTF-8 encode as a place where USVString applies. I haven't really countered another place, though the source does mention Rust subsystems as something where this might make sense, but since Rust isn't used on a large scale that's not super relevant yet.

@domenic
Copy link
Member

domenic commented May 11, 2017

So concretely, I think we should point out that USVString should be used for URLs or for strings that are to be sent "over the wire". I'm not sure what other scenarios there might be.

@SimonSapin
Copy link

For what it’s worth, Firefox’s ongoing style system rewrite uses UTF-8 strings internally. This effectively makes CSSOM strings be USVString. CSSWG resolved to allow both, so w3c/csswg-drafts#1266 introduced a CSSOMString typedef.

@domenic
Copy link
Member

domenic commented May 11, 2017

Right... I don't think we want to propogate such implementation-specific quirks throughout the platform via Web IDL advice.

@SimonSapin
Copy link

Right, CSSOMString probably does not have its place in this WebIDL spec note. This was only a response to "not sure what other scenarios there might be".

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Dec 5, 2018
This patch adjusts `ScriptURLString` to be a union including `USVString`,
not `DOMString`. The advice in [WebIDL][1] isn't exactly clear, but it
boils down to @domenic's notes in [whatwg/webidl#84][2] and
[w3ctag/design-principles#93][3].

Long story short, URLs are `USVString`. This patch adjusts our
implementation to match.

[1]: https://heycam.github.io/webidl/#idl-USVString
[2]: whatwg/webidl#84 (comment)
[3]: w3ctag/design-principles#93 (comment)

Change-Id: I9bf1240b421287d7d9c291b13d887ca981a66231
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Dec 6, 2018
This patch adjusts `ScriptURLString` to be a union including `USVString`,
not `DOMString`. The advice in [WebIDL][1] isn't exactly clear, but it
boils down to @domenic's notes in [whatwg/webidl#84][2] and
[w3ctag/design-principles#93][3].

Long story short, URLs are `USVString`. This patch adjusts our
implementation to match.

[1]: https://heycam.github.io/webidl/#idl-USVString
[2]: whatwg/webidl#84 (comment)
[3]: w3ctag/design-principles#93 (comment)

Change-Id: I9bf1240b421287d7d9c291b13d887ca981a66231
@jyasskin
Copy link
Member

jyasskin commented Dec 4, 2024

Is https://w3ctag.github.io/design-principles/#idl-string-types a sufficient fix for this?

@cynthia
Copy link

cynthia commented Dec 6, 2024

I believe so. We might have just forgot to close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
☕☕ difficulty:medium Hard to fix ⌛ duration:short Should be a short fix editorial Changes that do not affect how the standard is understood topic: string
Development

No branches or pull requests

7 participants