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

safari demo error (without-a-bundler-no-modules) #1825

Closed
cyanBone opened this issue Oct 21, 2019 · 7 comments · Fixed by #1829
Closed

safari demo error (without-a-bundler-no-modules) #1825

cyanBone opened this issue Oct 21, 2019 · 7 comments · Fixed by #1829
Labels

Comments

@cyanBone
Copy link

Summary

wasm-bindgen/examples/without-a-bundler-no-modules
This demo is successful in chrome, but there are errors in Safari

errors: Unhandled Promise Rejection: InvalidCharacterError: The string contains invalid characters.

Safari version 13.0.2

Additional Details

截屏2019-10-2111 59 00

@alexcrichton
Copy link
Contributor

Thanks for the report @cyanBone! I've updated the title of the issue here to reflect what's going on after debugging a bit. I turns out this JS snippet:

(new TextDecoder('utf-8', { ignoreBOM: true })).decode(new Uint8Array([112])).charCodeAt(0)

returns 65279 on Safari and 112 on Firefox. I believe the BOM is being included on the first use of TextDecoder on Safari whereas on other browsers it's only showing up if it was used. While this is likely a bug in Safari we should probably work around it ourselves locally.

@Pauan have you seen this before perchance? I figure the easiest thing to do would be to just decode something immediately to clear out the bom state on safari.

@Pauan
Copy link
Contributor

Pauan commented Oct 22, 2019

@alexcrichton Uh, wow, that's an incredible bug in Webkit. It seems that it's always including the BOM even if the BOM doesn't exist in the Uint8Array.

I can't test Safari, but could you also try these?

(new TextDecoder('utf-8', { ignoreBOM: false })).decode(new Uint8Array([])).charCodeAt(0)
(new TextDecoder('utf-8', { ignoreBOM: true })).decode(new Uint8Array([])).charCodeAt(0)
var decoder = new TextDecoder('utf-8', { ignoreBOM: true });
console.log(decoder.decode(new Uint8Array([112])).charCodeAt(0));
console.log(decoder.decode(new Uint8Array([112])).charCodeAt(0));

@alexcrichton
Copy link
Contributor

(new TextDecoder('utf-8', { ignoreBOM: false })).decode(new Uint8Array([])).charCodeAt(0)

Prints NaN

(new TextDecoder('utf-8', { ignoreBOM: true })).decode(new Uint8Array([])).charCodeAt(0)

Prints 65279

var decoder = new TextDecoder('utf-8', { ignoreBOM: true });
console.log(decoder.decode(new Uint8Array([112])).charCodeAt(0));
console.log(decoder.decode(new Uint8Array([112])).charCodeAt(0));

Prints 65279

then prints 112


Ok, sounds like we should probably just decode the empty array immediately to flush the bom out of the decoder?

@Pauan
Copy link
Contributor

Pauan commented Oct 22, 2019

Ok, sounds like we should probably just decode the empty array immediately to flush the bom out of the decoder?

Yeah, though we should have some extensive tests for this (decoding with BOM, decoding without BOM, decoding with BOM after not-BOM, etc.)

@cyanBone
Copy link
Author

@alexcrichton @Pauan

There is also wasm in golang. I can see from its JavaScript that it can run correctly. Here I give the JavaScript in golang.this javascritp has TextDecoder

https://github.com/golang/go/tree/master/misc/wasm

@Pauan
Copy link
Contributor

Pauan commented Oct 22, 2019

@cyanBone Yeah, that's because they don't use ignoreBOM: true, the bug with Safari only happens with ignoreBOM: true.

@Pauan
Copy link
Contributor

Pauan commented Oct 22, 2019

PR up: #1829 (I'd really like some unit tests though)

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

Successfully merging a pull request may close this issue.

3 participants