@@ -765,22 +765,19 @@ static bool ShouldTraceRegistryKey(const std::string& rawKey, const std::string&
765765 return StartsWith (registryKey, " node:" ) || StartsWith (registryKey, " blob:" );
766766}
767767
768- static std::string CanonicalizeRegistryKey (const std::string& rawKey ) {
769- if (rawKey .empty ()) {
770- return rawKey ;
768+ static std::string CanonicalizeRegistryKey (const std::string& key ) {
769+ if (key .empty ()) {
770+ return key ;
771771 }
772772
773- // Before any scheme test: a collapsed `http:/host` would otherwise fail the
774- // http tests below, fall through as a custom scheme, and give the module a
775- // second identity that never matches the resolver's.
776- const std::string key = RepairCollapsedUrlScheme (rawKey);
777-
778773 std::string registryKey;
779774 const char * classification = " path" ;
780775 bool traceEvenWithoutChange = false ;
781776
782- if (!NormalizeHttpModuleUrl (key).empty () || StartsWith (key, " file://http://" ) ||
783- StartsWith (key, " file://https://" )) {
777+ // Before any other scheme test: an http(s) URL in a spelling other than the
778+ // key's (`HTTP://`, `http:/host`) must not fall through as a custom scheme
779+ // and give the module a second identity.
780+ if (!NormalizeHttpModuleUrl (key).empty ()) {
784781 registryKey = CanonicalizeHttpUrlKey (key);
785782 classification = " http" ;
786783 } else if (StartsWith (key, " file://" )) {
@@ -1592,28 +1589,6 @@ static bool IsRegularFile(const std::string& p) {
15921589 return (st.st_mode & S_IFMT ) == S_IFREG ;
15931590}
15941591
1595- // Rebuild an HTTP URL a path join swallowed ('/app/http:/host/x' →
1596- // 'http://host/x'), or empty when the path embeds none.
1597- static std::string HttpUrlEmbeddedInPath (const std::string& p) {
1598- size_t pos1 = p.find (" /http:/" );
1599- size_t pos2 = p.find (" /https:/" );
1600- size_t pos = std::min (pos1 == std::string::npos ? SIZE_MAX : pos1,
1601- pos2 == std::string::npos ? SIZE_MAX : pos2);
1602- if (pos == SIZE_MAX ) {
1603- return " " ;
1604- }
1605- std::string tail = p.substr (pos + 1 );
1606- if (StartsWith (tail, " http:/" ) && !StartsWith (tail, " http://" )) {
1607- tail.insert (5 , " /" );
1608- } else if (StartsWith (tail, " https:/" ) && !StartsWith (tail, " https://" )) {
1609- tail.insert (6 , " /" );
1610- }
1611- if (!IsHttpRegistryKey (tail)) {
1612- return " " ;
1613- }
1614- return tail;
1615- }
1616-
16171592enum class ImportMapLookup {
16181593 kApply ,
16191594 kSkip , // the specifier is an existing module's origin, which the map never rewrites
@@ -1636,10 +1611,7 @@ static ModuleResolution ResolveSpecifierToPath(
16361611 return result;
16371612 }
16381613
1639- // Repair 'http:/host' (single slash) left by upstream path joins, so the URL
1640- // takes the HTTP path instead of becoming '/app/http:/host'. Shared with the
1641- // key derivations, so the resolver and the registry agree on one identity.
1642- std::string spec = RepairCollapsedUrlScheme (rawSpec);
1614+ std::string spec = rawSpec;
16431615
16441616 TNS_DEBUG (Esm, " [resolver][spec] %s" , spec.c_str ());
16451617
@@ -1850,14 +1822,6 @@ static ModuleResolution ResolveSpecifierToPath(
18501822 for (const std::string& baseCandidate : candidateBases) {
18511823 absPath = NormalizePath (baseCandidate);
18521824
1853- std::string embedded = HttpUrlEmbeddedInPath (absPath);
1854- if (!embedded.empty ()) {
1855- TNS_DEBUG (Esm, " [resolver][http-embedded] %s -> %s" , absPath.c_str (), embedded.c_str ());
1856- result.kind = ModuleResolution::Kind::kHttp ;
1857- result.url = embedded;
1858- return result;
1859- }
1860-
18611825 bool existsNow = IsRegularFile (absPath);
18621826 TNS_DEBUG (Esm, " [resolver] %s -> %s" , absPath.c_str (), existsNow ? " file" : " missing" );
18631827
@@ -3074,9 +3038,8 @@ static void FinishHttpDynamicImport(v8::Isolate* isolate, v8::Local<v8::Context>
30743038 // map. A local origin (`file:///app/…`) still has to become the absolute
30753039 // app path the registry keys by, or no scope would match it.
30763040 const std::string resourceName (*resourceUtf8);
3077- const std::string resourceUrl = RepairCollapsedUrlScheme (resourceName);
3078- if (!NormalizeHttpModuleUrl (resourceUrl).empty ()) {
3079- dynamicReferrerKey = CanonicalizeRegistryKey (resourceUrl);
3041+ if (!NormalizeHttpModuleUrl (resourceName).empty ()) {
3042+ dynamicReferrerKey = CanonicalizeRegistryKey (resourceName);
30803043 } else {
30813044 const ModuleResolution referrer =
30823045 ResolveSpecifierToPath (resourceName, std::string (), ImportMapLookup::kSkip );
@@ -3669,12 +3632,12 @@ static void FinishHttpDynamicImport(v8::Isolate* isolate, v8::Local<v8::Context>
36693632 return scope.Escape (resolver->GetPromise ());
36703633 }
36713634
3672- // The tail below re-resolves with no referrer, which would let an HTTP
3673- // importer's unmapped other-scheme specifier ('data:', 'file:/x') reach
3674- // ' <app>/<spec>' on disk. Only explicit file:// URLs and import-map
3675- // targets may continue into it.
3635+ // The tail below re-resolves with no referrer and joins relative
3636+ // specifiers onto the referrer as a path, which would let an HTTP
3637+ // importer's specifier reach ' <app>/<spec>' on disk or path-join an http
3638+ // URL. Only explicit file:// URLs may continue into it.
36763639 if (importerIsHttp && dynamicResolution.kind == ModuleResolution::Kind::kUnresolved &&
3677- normalizedSpec == rawSpec && !StartsWith (normalizedSpec, " file://" )) {
3640+ !StartsWith (normalizedSpec, " file://" )) {
36783641 resolver
36793642 ->Reject (context, v8::Exception::Error (tns::ToV8String (
36803643 isolate, UnresolvedModuleMessage (dynamicResolution))))
@@ -3745,9 +3708,6 @@ static void FinishHttpDynamicImport(v8::Isolate* isolate, v8::Local<v8::Context>
37453708 TNS_DEBUG (Esm, " [dyn-import][resolver-call] raw=%s normalized=%s adjusted=%s" ,
37463709 rawSpec.c_str (), normalizedSpec.c_str (), cAdj);
37473710 }
3748- v8::String::Utf8Value adjustedSpecUtf8 (isolate, adjustedSpecifier);
3749- std::string adjustedRegistryKey =
3750- *adjustedSpecUtf8 ? CanonicalizeRegistryKey (*adjustedSpecUtf8) : std::string ();
37513711 if (maybeModule.IsEmpty ()) {
37523712 if (resolveTc.HasCaught ()) {
37533713 // Reject the promise with the thrown exception so callers don't hang
0 commit comments