Skip to content

Subslice decodes entire array in IE11 #16

Open
@bwindels

Description

@bwindels
<!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?).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions