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

Support throwing exception from text method during UTF-8 decode #276

Closed
stevenatkin opened this issue Jun 29, 2017 · 3 comments
Closed

Support throwing exception from text method during UTF-8 decode #276

stevenatkin opened this issue Jun 29, 2017 · 3 comments
Labels
i18n-needs-resolution Issue the Internationalization Group has raised and looks for a response on.

Comments

@stevenatkin
Copy link

  1. PushMessageData interface

https://www.w3.org/TR/push-api/#pushmessagedata-interface

You should add support for an exception to the text() method. The text() method converts the bytes to UTF-8 using UTF-8 decode. If the UTF-8 byte sequence is malformed, then the text() method should throw an exception.

@r12a r12a added the i18n-needs-resolution Issue the Internationalization Group has raised and looks for a response on. label Jun 29, 2017
@beverloo
Copy link
Member

We depend on the UTF-8 decode operation defined in the Encoding spec. The default error mode for decoders is defined to be replacement instead of fatal, which means we shouldn't throw. Replacement characters will be inserted instead.

Is my reading correct, @annevk? That matches at least Chrome's implementation.

Would we want to explicitly override the error mode? I'm inclined not to, since our closest sibling method on Body doesn't either.

@annevk
Copy link
Member

annevk commented Aug 21, 2017

Yeah, we generally don't do that in the platform. Are the raw bytes exposed somewhere? If they are you can already get this kind of error handling if you want by using a TextDecoder object.

@beverloo
Copy link
Member

Yes, they're exposed. The following would work:

self.addEventListener('push', event => {
  const decoder = new TextDecoder('utf-8', {
    fatal: true
  });
  try {
    decoder.decode(event.data.arrayBuffer());
  } catch (e) {
    /* do something with |e| */
  }
});

Let me close this based on prior art and the availability of a way to get the exceptions if necessary. Happy to reconsider if you disagree!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
i18n-needs-resolution Issue the Internationalization Group has raised and looks for a response on.
Projects
None yet
Development

No branches or pull requests

4 participants