diff options
author | Denys Otrishko <shishugi@gmail.com> | 2018-08-16 20:19:06 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-09-17 17:41:42 +0200 |
commit | 1b92214d097358040efb7d3ec5dff1736f364bc0 (patch) | |
tree | 109aa3737c39b7fe47403ecdf761175d248ad6fc /test | |
parent | 3c2aa4b9f3a566c58d2958e96f239d59f509b50c (diff) | |
download | android-node-v8-1b92214d097358040efb7d3ec5dff1736f364bc0.tar.gz android-node-v8-1b92214d097358040efb7d3ec5dff1736f364bc0.tar.bz2 android-node-v8-1b92214d097358040efb7d3ec5dff1736f364bc0.zip |
module: fix inconsistency between load and _findPath
Files with multiple extensions are not handled by require-module system
therefore if you have file 'file.foo.bar' and require('./file') it won't
be found even while using require.extensions['foo.bar'] but before this
commit if you have require.extensions['foo.bar'] and
require.extensions['bar'] set then the latter will be called if you do
require('./file') but if you remove the former the former ('foo.bar')
property it will fail.
This commit makes it always fail in such cases.
Fixes: https://github.com/nodejs/node/issues/4778
PR-URL: https://github.com/nodejs/node/pull/22382
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'test')
-rw-r--r-- | test/known_issues/test-module-deleted-extensions.js | 18 | ||||
-rw-r--r-- | test/parallel/test-module-deleted-extensions.js | 58 |
2 files changed, 58 insertions, 18 deletions
diff --git a/test/known_issues/test-module-deleted-extensions.js b/test/known_issues/test-module-deleted-extensions.js deleted file mode 100644 index 3a51e8725e..0000000000 --- a/test/known_issues/test-module-deleted-extensions.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict'; -// Refs: https://github.com/nodejs/node/issues/4778 -const common = require('../common'); -const assert = require('assert'); -const fs = require('fs'); -const path = require('path'); -const tmpdir = require('../common/tmpdir'); -const file = path.join(tmpdir.path, 'test-extensions.foo.bar'); - -tmpdir.refresh(); -fs.writeFileSync(file, '', 'utf8'); -require.extensions['.foo.bar'] = (module, path) => {}; -delete require.extensions['.foo.bar']; -require.extensions['.bar'] = common.mustCall((module, path) => { - assert.strictEqual(module.id, file); - assert.strictEqual(path, file); -}); -require(path.join(tmpdir.path, 'test-extensions')); diff --git a/test/parallel/test-module-deleted-extensions.js b/test/parallel/test-module-deleted-extensions.js new file mode 100644 index 0000000000..f14da0a70f --- /dev/null +++ b/test/parallel/test-module-deleted-extensions.js @@ -0,0 +1,58 @@ +'use strict'; + +// Refs: https://github.com/nodejs/node/issues/4778 + +const common = require('../common'); +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); +const tmpdir = require('../common/tmpdir'); +const file = path.join(tmpdir.path, 'test-extensions.foo.bar'); + +tmpdir.refresh(); +fs.writeFileSync(file, '', 'utf8'); + +{ + require.extensions['.bar'] = common.mustNotCall(); + require.extensions['.foo.bar'] = common.mustNotCall(); + const modulePath = path.join(tmpdir.path, 'test-extensions'); + assert.throws( + () => require(modulePath), + new Error(`Cannot find module '${modulePath}'`) + ); +} + +{ + delete require.extensions['.bar']; + require.extensions['.foo.bar'] = common.mustNotCall(); + const modulePath = path.join(tmpdir.path, 'test-extensions'); + assert.throws( + () => require(modulePath), + new Error(`Cannot find module '${modulePath}'`) + ); + assert.throws( + () => require(modulePath + '.foo'), + new Error(`Cannot find module '${modulePath}.foo'`) + ); +} + +{ + delete require.extensions['.bar']; + delete require.extensions['.foo.bar']; + const modulePath = path.join(tmpdir.path, 'test-extensions'); + assert.throws( + () => require(modulePath), + new Error(`Cannot find module '${modulePath}'`) + ); +} + +{ + delete require.extensions['.foo.bar']; + require.extensions['.bar'] = common.mustCall((module, path) => { + assert.strictEqual(module.id, file); + assert.strictEqual(path, file); + }); + + const modulePath = path.join(tmpdir.path, 'test-extensions.foo'); + require(modulePath); +} |