Logo
Explore Help
Sign In
1berry/nodejs
1
0
Fork 0
You've already forked nodejs
Code Issues Packages Projects Releases Wiki Activity
nodejs/test/parallel/test-require-resolve-invalid-paths.js

19 lines
405 B
JavaScript
Raw Permalink Normal View History

module: fix require.resolve() crash on non-string paths Previously, `require.resolve()` could crash when: - The first parameter was a relative path and - The `paths` array contained non-string entries This commit fixes the issue by adding a check in `Module._findPath` to ensure all elements in `paths` are strings, and adding a validation in `stat` before calling `InternalModuleStat` to guard against non-string filenames. PR-URL: https://github.com/nodejs/node/pull/56942 Fixes: https://github.com/nodejs/node/issues/47698 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2025-02-11 20:54:02 +05:30
'use strict';
require('../common');
const assert = require('assert');
// Test invalid `paths` entries: Ensure non-string entries throw an error
{
const paths = [1, false, null, undefined, () => {}, {}];
paths.forEach((value) => {
assert.throws(
() => require.resolve('.', { paths: [value] }),
{
name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
}
);
});
}
Reference in New Issue Copy Permalink
Powered by Gitea Version: 1.23.8 Page: 638ms Template: 3ms
English
Bahasa Indonesia Deutsch English Español Français Gaeilge Italiano Latviešu Magyar nyelv Nederlands Polski Português de Portugal Português do Brasil Suomi Svenska Türkçe Čeština Ελληνικά Български Русский Українська فارسی മലയാളം 日本語 简体中文 繁體中文(台灣) 繁體中文(香港) 한국어
Licenses API