mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
assert: do not read Node.js modules
Prevent reading a Node.js module. That could theoretically lead to false errors being thrown otherwise. PR-URL: https://github.com/nodejs/node/pull/18322 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
3 files changed
+100
-50
No files matched your search
@@ -19,6 +19,8 @@
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// Flags: --expose-internals
|
||||
|
||||
'use strict';
|
||||
|
||||
/* eslint-disable prefer-common-expectserror */
|
||||
@@ -26,6 +28,9 @@
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const { EOL } = require('os');
|
||||
const EventEmitter = require('events');
|
||||
const { errorCache } = require('internal/errors');
|
||||
const { writeFileSync, unlinkSync } = require('fs');
|
||||
const a = assert;
|
||||
|
||||
function makeBlock(f) {
|
||||
@@ -1019,6 +1024,38 @@ common.expectsError(
|
||||
}
|
||||
);
|
||||
|
||||
// Do not try to check Node.js modules.
|
||||
{
|
||||
const e = new EventEmitter();
|
||||
|
||||
e.on('hello', assert);
|
||||
|
||||
let threw = false;
|
||||
try {
|
||||
e.emit('hello', false);
|
||||
} catch (err) {
|
||||
const frames = err.stack.split('\n');
|
||||
const [, filename, line, column] = frames[1].match(/\((.+):(\d+):(\d+)\)/);
|
||||
// Reset the cache to check again
|
||||
errorCache.delete(`${filename}${line - 1}${column - 1}`);
|
||||
const data = `${'\n'.repeat(line - 1)}${' '.repeat(column - 1)}` +
|
||||
'ok(failed(badly));';
|
||||
try {
|
||||
writeFileSync(filename, data);
|
||||
assert.throws(
|
||||
() => e.emit('hello', false),
|
||||
{
|
||||
message: 'false == true'
|
||||
}
|
||||
);
|
||||
threw = true;
|
||||
} finally {
|
||||
unlinkSync(filename);
|
||||
}
|
||||
}
|
||||
assert(threw);
|
||||
}
|
||||
|
||||
common.expectsError(
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
() => assert.throws(() => {}, 'Error message', 'message'),
|
||||
|
||||
Reference in new issue
Block a user