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

Subslice decodes entire array in IE11 #16

Open
bwindels opened this issue Sep 18, 2020 · 0 comments
Open

Subslice decodes entire array in IE11 #16

bwindels opened this issue Sep 18, 2020 · 0 comments

Comments

@bwindels
Copy link

bwindels commented Sep 18, 2020

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
</head>
<body>
    <script src="https://dl.dropboxusercontent.com/s/r55397ld512etib/EncoderDecoderTogether.min.js?dl=0" nomodule="" type="text/javascript"></script>
    <script type="text/javascript">
        const bytes = [50,65,113,117,121,81,111,98,118,68,76,43,77,110,73,90,49,100,43,77,65,71,119,87,68,82,115,57,74,54,117,97,79,78,120,74,119,54,88,113,120,86,99];
        var allBytes = new Uint8Array(16777216);
        // write some A's to the beginning
        for (var i = 100 - 1; i >= 0; i--) {
            allBytes[i] = 65;
        }

        const offset = 242839;
        for (var i = bytes.length - 1; i >= 0; i--) {
            allBytes[i + offset] = bytes[i];
        }
        const slice = allBytes.subarray(offset, offset + bytes.length);
        console.log("slice", slice.length, slice[0], slice);
        const str = new TextDecoder().decode(slice);
        console.log("str", str.length, str);
    </script>
</body>
</html>

Output on IE11:

slice 43 50 [object Uint8Array]
str 16777216 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

Output in Firefox 80 (expected output):

slice 43 50 Uint8Array(43) [ 50, 65, 113, 117, 121, 81, 111, 98, 118, 68, … ]
str 43 2AquyQobvDL+MnIZ1d+MAGwWDRs9J6uaONxJw6XqxVc

As you can see, on IE11, the slice returned from subarray has the correct length and correct first byte, but somehow decode decodes the entire allBytes array (until it finds a 0 byte?).

@bwindels bwindels changed the title Subslice decodes to entire array in IE11 Subslice decodes entire array in IE11 Sep 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant