@@ -591,14 +591,14 @@ void BindingData::GetPackageScopeConfig(
591591 return ;
592592 }
593593
594- // Walking one string avoids a URL parse per directory level.
594+ // Avoids a URL parse per level.
595595 std::string& path = *file_path;
596596 static constexpr std::string_view kPackageJSON = " package.json" ;
597597 size_t root_end = 0 ;
598598#ifdef _WIN32
599599 static constexpr std::string_view kNodeModulesPackagePath =
600600 " \\ node_modules\\ package.json" ;
601- // Do not walk above the drive ("C:") or the UNC host ("\\host").
601+ // Stop at the drive ("C:") or UNC host ("\\host").
602602 root_end = path.starts_with (" \\\\ " ) ? path.find (' \\ ' , 2 ) : 2 ;
603603#else
604604 static constexpr std::string_view kNodeModulesPackagePath =
@@ -607,13 +607,12 @@ void BindingData::GetPackageScopeConfig(
607607
608608 while (!path.ends_with (kNodeModulesPackagePath )) {
609609#ifdef _WIN32
610- // Cache keys must match the namespaced paths ReadPackageJSON() inserts.
611- // TODO(araujogui): This creates a V8 string per level. Add a string
612- // ToNamespacedPath() overload if it shows up in profiles.
610+ // Cache keys are namespaced.
611+ // TODO(araujogui): Add a std::string ToNamespacedPath() overload.
613612 BufferValue file_path_buf (realm->isolate (),
614613 String::NewFromUtf8 (realm->isolate (),
615614 path.c_str (),
616- NewStringType::kInternalized ,
615+ NewStringType::kNormal ,
617616 path.size ())
618617 .ToLocalChecked ());
619618 ToNamespacedPath (realm->env (), &file_path_buf);
@@ -638,7 +637,13 @@ void BindingData::GetPackageScopeConfig(
638637 if (dir_end <= root_end) {
639638 break ;
640639 }
641- path.resize (path.rfind (kPathSeparator , dir_end - 1 ) + 1 );
640+ const size_t parent_end = path.rfind (kPathSeparator , dir_end - 1 );
641+ // Drive-relative, from "file:///C:foo/x.js". The URL walk threw here.
642+ if (parent_end == std::string::npos) {
643+ url::ThrowInvalidURL (realm->env (), resolved.ToStringView (), std::nullopt );
644+ return ;
645+ }
646+ path.resize (parent_end + 1 );
642647 path += kPackageJSON ;
643648 }
644649
0 commit comments