-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR-URL: #14455 Reviewed-By: Anna Henningsen <anna@addaleax.net>
- Loading branch information
1 parent
f35f06d
commit 68cf7f0
Showing
7 changed files
with
226 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,39 @@ | ||
'use strict'; | ||
// test uncompressing invalid input | ||
|
||
require('../common'); | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const zlib = require('zlib'); | ||
|
||
const nonStringInputs = [1, true, {a: 1}, ['a']]; | ||
const nonStringInputs = [ | ||
1, | ||
true, | ||
{ a: 1 }, | ||
['a'] | ||
]; | ||
|
||
console.error('Doing the non-strings'); | ||
nonStringInputs.forEach(function(input) { | ||
// zlib.Unzip classes need to get valid data, or else they'll throw. | ||
const unzips = [ | ||
zlib.Unzip(), | ||
zlib.Gunzip(), | ||
zlib.Inflate(), | ||
zlib.InflateRaw() | ||
]; | ||
|
||
nonStringInputs.forEach(common.mustCall((input) => { | ||
// zlib.gunzip should not throw an error when called with bad input. | ||
assert.doesNotThrow(function() { | ||
zlib.gunzip(input, function(err, buffer) { | ||
// zlib.gunzip should pass the error to the callback. | ||
assert.ok(err); | ||
}); | ||
}); | ||
}); | ||
}, nonStringInputs.length)); | ||
|
||
console.error('Doing the unzips'); | ||
// zlib.Unzip classes need to get valid data, or else they'll throw. | ||
const unzips = [ zlib.Unzip(), | ||
zlib.Gunzip(), | ||
zlib.Inflate(), | ||
zlib.InflateRaw() ]; | ||
const hadError = []; | ||
unzips.forEach(function(uz, i) { | ||
console.error(`Error for ${uz.constructor.name}`); | ||
uz.on('error', function(er) { | ||
console.error('Error event', er); | ||
hadError[i] = true; | ||
}); | ||
|
||
uz.on('end', function(er) { | ||
throw new Error(`end event should not be emitted ${uz.constructor.name}`); | ||
}); | ||
unzips.forEach(common.mustCall((uz, i) => { | ||
uz.on('error', common.mustCall()); | ||
uz.on('end', common.mustNotCall); | ||
|
||
// this will trigger error event | ||
uz.write('this is not valid compressed data.'); | ||
}); | ||
|
||
process.on('exit', function() { | ||
assert.deepStrictEqual(hadError, [true, true, true, true], 'expect 4 errors'); | ||
}); | ||
}, unzips.length)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.