1eb615411838193436b51e2a8a177b865544d85d
chmalee
  Fri Jun 25 14:33:38 2021 -0700
Fix bug in trackDb include processing, when a bigDataUrl is referenced relative to it's trackDb file, and the trackDb file is referenced via an include statement, CGIs were trying to expand bigDataUrl relative to the top level trackDb instead of it's correct parent, refs #27767

diff --git src/hg/lib/trackDbCustom.c src/hg/lib/trackDbCustom.c
index 396b9ed..b7bfd9b 100644
--- src/hg/lib/trackDbCustom.c
+++ src/hg/lib/trackDbCustom.c
@@ -10,30 +10,31 @@
 #include "linefile.h"
 #include "jksql.h"
 #include "trackDb.h"
 #include "hdb.h"
 #include "hui.h"
 #include "ra.h"
 #include "hash.h"
 #include "net.h"
 #include "sqlNum.h"
 #include "obscure.h"
 #include "hgMaf.h"
 #include "customTrack.h"
 #include "regexHelper.h"
 #include "fieldedTable.h"
 #include "tagRepo.h"
+#include "htmlPage.h"
 
 struct trackDb *trackDbNew()
 /* Allocate a new trackDb with just very minimal stuff filled in. */
 {
 struct trackDb *tdb;
 AllocVar(tdb);
 tdb->canPack = 2;	/* Unknown value. */
 return tdb;
 }
 
 int trackDbCmp(const void *va, const void *vb)
 /* Compare to sort based on priority; use shortLabel as secondary sort key.
  * Note: parallel code to hgTracks.c:tgCmpPriority */
 {
 const struct trackDb *a = *((struct trackDb **)va);
@@ -104,37 +105,45 @@
         errAbort("invalid track line: %s:%d: track %s", lf->fileName, lf->lineIx, value);
     bt->overrides = hashNew(0);
     }
 }
 
 static void trackDbAddRelease(struct trackDb *bt, char *releaseTag)
 /* Add release tag */
 {
 hashAdd(bt->settingsHash, "release", cloneString(releaseTag));
 }
 
 static void trackDbAddInfo(struct trackDb *bt,
         char *var, char *value, struct lineFile *lf)
 /* Add info from a variable/value pair to browser table. */
 {
+char *subbedUrl = NULL;
 if (sameString(var, "track"))
     parseTrackLine(bt, value, lf);
+
+// Since we may have gotten here from an include statement, we
+// need to expand the url relative to the include statement, and
+// not later where the url will be expanded relative to the parent
+// of the include statement
+if (trackSettingIsFile(var))
+    subbedUrl = htmlExpandUrl(lf->fileName, value);
 if (bt->settingsHash == NULL)
     bt->settingsHash = hashNew(7);
 if (bt->viewHash == NULL)
     bt->viewHash = hashNew(7);
-char *storeValue = cloneString(value);
+char *storeValue = cloneString(subbedUrl != NULL ? subbedUrl : value);
 
 // squirrel away views
 if (startsWith("subGroup", var))
     {
     char *ptr = strchr(value, ' ');
     if (ptr)
         *ptr = 0;
     hashAdd(bt->viewHash, value, storeValue);
     if (ptr)
         *ptr = ' ';
     }
 
 hashAdd(bt->settingsHash, var, storeValue);
 
 if (bt->overrides != NULL)