Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6b53efb

Browse filesBrowse files
StefanStojanovicaduh95
authored andcommitted
module,win: fix long subpath import
Fixes: #62043 PR-URL: #62101 Fixes: #62043 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
1 parent 1fee265 commit 6b53efb
Copy full SHA for 6b53efb

3 files changed

+51-3Lines changed: 51 additions & 3 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/node_modules.cc‎

Copy file name to clipboardExpand all lines: src/node_modules.cc
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,16 @@ void BindingData::GetPackageScopeConfig(
426426
url::ThrowInvalidURL(realm->env(), resolved.ToStringView(), std::nullopt);
427427
return;
428428
}
429+
BufferValue file_path_buf(realm->isolate(),
430+
String::NewFromUtf8(realm->isolate(),
431+
file_url->c_str(),
432+
NewStringType::kInternalized,
433+
file_url->size())
434+
.ToLocalChecked());
435+
ToNamespacedPath(realm->env(), &file_path_buf);
429436
error_context.specifier = resolved.ToString();
430-
auto package_json = GetPackageJSON(realm, *file_url, &error_context);
437+
auto package_json =
438+
GetPackageJSON(realm, file_path_buf.ToStringView(), &error_context);
431439
if (package_json != nullptr) {
432440
if constexpr (return_only_type) {
433441
Local<Value> value;
Collapse file

‎test/es-module/test-esm-long-path-win.js‎

Copy file name to clipboardExpand all lines: test/es-module/test-esm-long-path-win.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('long path on Windows', () => {
6060
tmpdir.refresh();
6161

6262
fs.mkdirSync(packageDirPath);
63-
fs.writeFileSync(packageJSPath, '');
63+
fs.writeFileSync(packageJSPath, '{}');
6464
fs.writeFileSync(indexJSPath, '');
6565

6666
const packageJsonUrl = pathToFileURL(
@@ -83,7 +83,7 @@ describe('long path on Windows', () => {
8383
tmpdir.refresh();
8484

8585
fs.mkdirSync(packageDirPath);
86-
fs.writeFileSync(packageJSPath, '');
86+
fs.writeFileSync(packageJSPath, '{}');
8787
fs.writeFileSync(indexJSPath, '');
8888

8989
const packageJsonUrl = pathToFileURL(
Collapse file
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Regression test for https://github.com/nodejs/node/issues/62043
2+
'use strict';
3+
4+
const common = require('../common');
5+
if (!common.isWindows) {
6+
common.skip('this test is Windows-specific.');
7+
}
8+
9+
const fs = require('fs');
10+
const { createRequire } = require('module');
11+
const path = require('path');
12+
const tmpdir = require('../common/tmpdir');
13+
14+
tmpdir.refresh();
15+
16+
const TARGET = 260; // Shortest length that used to trigger the bug
17+
const fixedLen = tmpdir.path.length + 2 + 'package.json'.length;
18+
const dirNameLen = Math.max(TARGET - fixedLen, 1);
19+
20+
const dir = path.join(tmpdir.path, 'a'.repeat(dirNameLen));
21+
const depDir = path.join(dir, 'node_modules', 'dep');
22+
const packageJsonPath = path.join(dir, 'package.json');
23+
24+
fs.mkdirSync(depDir, { recursive: true });
25+
fs.writeFileSync(
26+
packageJsonPath,
27+
JSON.stringify({ imports: { '#foo': './foo.mjs' } }),
28+
);
29+
fs.writeFileSync(path.join(dir, 'foo.mjs'), 'export default 1;\n');
30+
fs.writeFileSync(
31+
path.join(depDir, 'package.json'),
32+
JSON.stringify({ name: 'dep', exports: { '.': './index.mjs' } }),
33+
);
34+
fs.writeFileSync(path.join(depDir, 'index.mjs'), 'export default 1;\n');
35+
36+
const req = createRequire(path.join(dir, '_.mjs'));
37+
38+
// Both resolves should succeed without throwing
39+
req.resolve('dep');
40+
req.resolve('#foo');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.