@@ -777,8 +777,9 @@ static bool ShouldTraceRegistryKey(const std::string& rawKey, const std::string&
777777 // Before any other scheme test: an http(s) URL in a spelling other than the
778778 // key's (`HTTP://`, `http:/host`) must not fall through as a custom scheme
779779 // and give the module a second identity.
780- if (!NormalizeHttpModuleUrl (key).empty ()) {
781- registryKey = CanonicalizeHttpUrlKey (key);
780+ const std::string httpUrl = NormalizeHttpModuleUrl (key);
781+ if (!httpUrl.empty ()) {
782+ registryKey = CanonicalizeNormalizedHttpUrlKey (httpUrl);
782783 classification = " http" ;
783784 } else if (StartsWith (key, " file://" )) {
784785 registryKey = NormalizePath (FileURLToPath (key));
@@ -812,15 +813,13 @@ static bool ShouldTraceRegistryKey(const std::string& rawKey, const std::string&
812813
813814v8::MaybeLocal<v8::Module> LoadHttpModuleForUrl (v8::Isolate* isolate,
814815 v8::Local<v8::Context> context,
815- const std::string& requestedUrlArg ) {
816+ const std::string& requestedUrl ) {
816817 auto * moduleState = ModuleLoaderStateFor (isolate);
817818 if (moduleState == nullptr ) {
818819 return v8::MaybeLocal<v8::Module>();
819820 }
820821 auto & registry = moduleState->registry ;
821- const std::string normalizedUrl = NormalizeHttpModuleUrl (requestedUrlArg);
822- const std::string& requestedUrl = normalizedUrl.empty () ? requestedUrlArg : normalizedUrl;
823- const std::string registryKey = CanonicalizeHttpUrlKey (requestedUrl);
822+ const std::string registryKey = CanonicalizeNormalizedHttpUrlKey (requestedUrl);
824823
825824 TNS_DEBUG (Esm, " [http-esm][load][begin] request=%s key=%s" , requestedUrl.c_str (),
826825 registryKey.c_str ());
@@ -1974,7 +1973,7 @@ static void AsyncGraphOnFetchCompleted(const std::shared_ptr<AsyncGraphLoad>& lo
19741973
19751974 load->pendingFetches --;
19761975
1977- const std::string key = CanonicalizeHttpUrlKey (url);
1976+ const std::string key = CanonicalizeNormalizedHttpUrlKey (url);
19781977 const bool isRoot = (key == load->rootKey );
19791978
19801979 if (!load->failed ) {
@@ -2096,10 +2095,11 @@ static void AsyncGraphEnqueue(const std::shared_ptr<AsyncGraphLoad>& load,
20962095 const ModuleResolution& resolution) {
20972096 const bool isHttp = resolution.kind == ModuleResolution::Kind::kHttp ;
20982097 const std::string& target = isHttp ? resolution.url : resolution.path ;
2099- // One keying function for both schemes: it dispatches to the HTTP canonical
2100- // key for URLs and to the normalized path otherwise, so the walk registers
2101- // every module under the exact key the resolver will look up.
2102- const std::string key = CanonicalizeRegistryKey (target);
2098+ // The keys CanonicalizeRegistryKey gives these targets, so the walk registers
2099+ // every module under the exact key the resolver will look up; a resolved
2100+ // URL is already spelled, so only its vocabulary is applied.
2101+ const std::string key =
2102+ isHttp ? CanonicalizeNormalizedHttpUrlKey (target) : CanonicalizeRegistryKey (target);
21032103 if (!load->visited .insert (key).second ) {
21042104 return ;
21052105 }
@@ -2207,10 +2207,13 @@ void StartModuleGraphLoad(
22072207 double fetchDeadline,
22082208 std::function<void (bool ok, const std::string& errorMessage, v8::Local<v8::Context> context)>
22092209 onComplete) {
2210+ const ModuleResolution rootResolution = ResolutionForRoot (root);
22102211 auto load = std::make_shared<AsyncGraphLoad>();
22112212 load->isolate = isolate;
22122213 load->context .Reset (isolate, context);
2213- load->rootKey = CanonicalizeRegistryKey (root);
2214+ load->rootKey = rootResolution.kind == ModuleResolution::Kind::kHttp
2215+ ? CanonicalizeNormalizedHttpUrlKey (rootResolution.url )
2216+ : CanonicalizeRegistryKey (root);
22142217 load->startUs = (uint64_t )(CFAbsoluteTimeGetCurrent () * 1000.0 * 1000.0 );
22152218 load->fetchDeadline = fetchDeadline;
22162219 load->onComplete = std::move (onComplete);
@@ -2220,7 +2223,6 @@ void StartModuleGraphLoad(
22202223
22212224 TNS_DEBUG (Esm, " [graph][start] root=%s key=%s" , root.c_str (), load->rootKey .c_str ());
22222225
2223- const ModuleResolution rootResolution = ResolutionForRoot (root);
22242226 if (rootResolution.kind != ModuleResolution::Kind::kUnresolved ) {
22252227 AsyncGraphEnqueue (load, rootResolution);
22262228 }
@@ -3462,7 +3464,7 @@ static void FinishHttpDynamicImport(v8::Isolate* isolate, v8::Local<v8::Context>
34623464 // Security: HttpFetchModule gates remote module access centrally.
34633465 if (dynamicResolution.kind == ModuleResolution::Kind::kHttp ) {
34643466 TNS_DEBUG (Esm, " [dyn-import][http-loader] trying URL %s" , normalizedSpec.c_str ());
3465- std::string key = CanonicalizeHttpUrlKey (normalizedSpec);
3467+ std::string key = CanonicalizeNormalizedHttpUrlKey (normalizedSpec);
34663468 // Volatile pattern check: if the URL matches any configured volatile
34673469 // pattern, evict the cached module so we always re-fetch. The pattern
34683470 // list is policy and is supplied exclusively by the dev client via
0 commit comments