dad13f95ddaaa0f9c9b111fdc6454b0a3053c1c0
chmalee
  Tue Oct 31 10:56:18 2023 -0700
Fix broken tables on hgc pages for tracks with the detailsDynamicTable setting, refs #32269,#32519

diff --git src/hg/hgc/hgc.c src/hg/hgc/hgc.c
index 2145bb4..c6f4c73 100644
--- src/hg/hgc/hgc.c
+++ src/hg/hgc/hgc.c
@@ -1870,30 +1870,34 @@
         strcpy(replaceField+2, fieldName);
         replaceField[fieldLen+2] = '}';
         replaceField[fieldLen+3] = 0;
         extraTbl2Str = dyStringSub(extraTbl2Str->string, replaceField, fields[ix]);
         continue;
         }
 
     // similar to above, if the field contains an embedded table skip it here
     // and print it later
     if (embeddedTblFields)
         {
         struct embeddedTbl *new = hashFindVal(embeddedTblHash, fieldName);
         if (new)
             {
             new->encodedTbl = fields[ix];
+            // this field will get printed later somehow, so make sure the
+            // rest of this code knows to not open more table tags and close
+            // the correct ones
+            printCount++;
             continue;
             }
         }
 
     // do not print a row if the fieldName from the .as file is in the "skipFields" list
     // or if a field name starts with _. This makes bigBed extra fields consistent with
     // external extra fields in that _ field names have some meaning and are not shown
     if (startsWith("_", fieldName) || (skipIds && slNameInList(skipIds, fieldName)))
         continue;
 
     // skip this row if it's empty and "skipEmptyFields" option is set
     if (skipEmptyFields && isEmpty(fields[ix]))
         continue;
 
     if (printCount == 0)
@@ -1924,31 +1928,30 @@
         else
             printf("<td>%s</td></tr>\n", fields[ix]); // decided not to print error
         }
     else
         printf("<td class='bedExtraTblVal'>%s</td></tr>\n", fields[ix]);
     printCount++;
     }
 if (skipIds)
     slFreeList(skipIds);
 if (sepFields)
     slFreeList(sepFields);
 
 if (embeddedTblFields)
     {
     printf("<br><table class='bedExtraTbl'>\n");
-    printf("</table>\n");
 
     struct embeddedTbl *thisTbl;
     struct dyString *tableLabelsDy = dyStringNew(0);
     for (thisTbl = embeddedTblList; thisTbl != NULL; thisTbl = thisTbl->next)
         {
         if (thisTbl->encodedTbl)
             {
             dyStringPrintf(tableLabelsDy, "var _jsonHgcLabels = [");
             printEmbeddedTable(tdb, thisTbl, tableLabelsDy);
             dyStringPrintf(tableLabelsDy, "];\n");
             }
         }
 
     jsInline(dyStringCannibalize(&tableLabelsDy));
     }