e08ae97dc288749c2454fd98a10dc79f06e27cb5
max
  Tue Aug 11 06:16:20 2026 -0700
hgBlat/hgc: fixes from the v502 code review of the BLAT results pages, refs #37893

#4 blatOldTracks now falls back to "keep" (with a warning) on any value other
than keep/hide/delete, instead of dropping into the destructive delete branch,
so a typo in hg.conf can never silently discard a user's earlier BLAT tracks.

#5 htmlEncode() (js/utils.js) now also escapes " and ', which the browser's
text->markup conversion leaves alone. Every hgBlat caller puts the result in a
double-quoted attribute, so an unescaped quote in the cart position string could
break out of the attribute; the shared helper now honors its documented contract.

#6 The non-BLAT alignment title no longer starts with a stray space.

#7 open_memstream() is checked for NULL: on that failure the alignment renders
straight to stdout instead of writing to a NULL FILE and calling fclose(NULL).
The section reorder keys on the literal "<H4><A NAME=genomic>"/"<H4><A NAME=ali>"
strings, so a note was added in fuzzyShow.c and pslShow.c to keep them intact.

Found in the v502 final-build code review, refs #38069.

diff --git src/lib/fuzzyShow.c src/lib/fuzzyShow.c
index 59e385177db..d792f50917d 100644
--- src/lib/fuzzyShow.c
+++ src/lib/fuzzyShow.c
@@ -287,30 +287,32 @@
     reverseComplement(needle, needleSize);
 
 if (showNeedle)
     {
     ffShNeedle(f, needle, needleSize, needleNumOffset, colorFlags,
 	       aliList, upcMatch, cdsS, cdsE,
 	       restrictToWindow, nPartS, nPartE);
     }
 
 if (showHaystack)
     {
     struct cfm *cfm = cfmNew(10, 50, TRUE, rcHaystack, f, hayExtremity);
     char *h = cloneMem(haystack, haySize);
     char *accentFlags = needMem(haySize);
     zeroBytes(accentFlags, haySize);
+    /* hgc's htcBlatAlignment reorders these sections by matching the literal "<H4><A NAME=genomic>"
+     * and "<H4><A NAME=ali>" prefixes; keep them intact (or update hgc.c) so the reorder still fires. */
     fprintf(f, "<H4><A NAME=genomic></A>Genomic %s %s:</H4>\n",
     	haystackName,
 	(rcHaystack ? "(reverse strand)" : ""));
     fprintf(f, "<PRE><TT>\n");
     zeroBytes(colorFlags, haySize);
     for (ali = leftAli; ali != NULL; ali = ali->right)
 	{
 	boolean utr = FALSE;
 	int i;
 	int off = ali->hStart-haystack;
 	int count = ali->hEnd - ali->hStart;
 	int offn = ali->nStart-needle;
 	if ((cdsE > 0) && ((cdsS-offn-1) > 0)) 
 	    utr = TRUE;
 	for (i=0; i<count; ++i)