ea82eeb86ad5cf92ddf795f2d6f9ce84e33e52d5
chmalee
  Wed Jul 29 11:20:16 2026 -0700
Stop hubApi /search from crashing on position matches and curated hub genomes. refs #37956

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

diff --git src/hg/lib/trackHub.c src/hg/lib/trackHub.c
index 8ef7f5b5a10..49a69f76283 100644
--- src/hg/lib/trackHub.c
+++ src/hg/lib/trackHub.c
@@ -395,34 +395,39 @@
 slFreeList(&chromList);
 
 return defaultName;
 }
 
 static struct twoBitFile *openTwoBit(struct trackHubGenome *genome)
 /* Open a twoBit file that may or may not have a bpt index. */
 {
 if (genome->twoBitBptUrl)
     return twoBitOpenExternalBptIndex(genome->twoBitPath, genome->twoBitBptUrl);
 else
     return twoBitOpen(genome->twoBitPath);
 }
 
 struct chromInfo *trackHubMaybeChromInfo(char *database, char *chrom)
-/* Return a chromInfo structure for just this chrom in this database. 
+/* Return a chromInfo structure for just this chrom in this database.  The database
+ * may be decorated with a hub_<id>_ prefix or undecorated.
  * Return NULL if chrom doesn't exist. */
 {
-struct trackHubGenome *genome = trackHubGetGenome(database);
+struct trackHubGenome *genome = NULL;
+if (hubAssemblyHash != NULL)
+    genome = trackHubGetGenome(database);
+if (genome == NULL)
+    genome = trackHubGetGenomeUndecorated(trackHubSkipHubName(database));
 if (genome == NULL)
     return NULL;
 
 if (genome->tbf == NULL)
     genome->tbf = openTwoBit(genome);
 if (!twoBitIsSequence(genome->tbf, chrom))
     return NULL;
 
 struct chromInfo *ci;
 AllocVar(ci);
 ci->chrom = cloneString(chrom);
 ci->fileName = genome->twoBitPath;
 ci->size = twoBitSeqSize(genome->tbf, chrom);
 
 return ci;