code review: mind length of data available

This commit is contained in:
Raymond Hill 2017-12-29 20:33:24 -05:00
parent b36320c643
commit a3f7392f06
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 3 additions and 6 deletions

View File

@ -603,6 +603,7 @@ var filterDocument = (function() {
} }
// We need to insert after DOCTYPE, or else the browser may falls into // We need to insert after DOCTYPE, or else the browser may falls into
// quirks mode. // quirks mode.
if ( responseBytes.byteLength < 256 ) { return false; }
var bb = new Uint8Array(responseBytes, 0, 256), var bb = new Uint8Array(responseBytes, 0, 256),
i = 0, b; i = 0, b;
// Skip BOM if present. // Skip BOM if present.
@ -638,15 +639,11 @@ var filterDocument = (function() {
if ( (qcount & 1) !== 0 ) { return false; } if ( (qcount & 1) !== 0 ) { return false; }
// We found a valid insertion point. // We found a valid insertion point.
if ( textEncoder === undefined ) { textEncoder = new TextEncoder(); } if ( textEncoder === undefined ) { textEncoder = new TextEncoder(); }
filterer.stream.write( filterer.stream.write(new Uint8Array(responseBytes, 0, i));
new Uint8Array(responseBytes, 0, i)
);
filterer.stream.write( filterer.stream.write(
textEncoder.encode('<script>' + filterer.scriptlets + '</script>') textEncoder.encode('<script>' + filterer.scriptlets + '</script>')
); );
filterer.stream.write( filterer.stream.write(new Uint8Array(responseBytes, i));
new Uint8Array(responseBytes, i)
);
filterer.stream.disconnect(); filterer.stream.disconnect();
return true; return true;
}; };