48272e481ae9768378a88da5019d61706e9feb9c
angie
  Fri Mar 10 11:12:53 2017 -0800
Libify the hgTables fix for problematic characters in download filenames and apply to hgVai, hgIntegrator and hgSession.  Thanks Jairo! refs #18931 note-10

diff --git src/hg/hgTables/hgTables.c src/hg/hgTables/hgTables.c
index a54119f..148a94c 100644
--- src/hg/hgTables/hgTables.c
+++ src/hg/hgTables/hgTables.c
@@ -222,35 +222,31 @@
 char *script = cgiScriptName();
 if (script != NULL)
     return script;
 else
     return hgTablesName();
 }
 
 
 void textOpen()
 /* Start up page in text format. (No need to close this).
  *	In case of pipeline output to a compressor, it is closed
  *	at main() exit.
  */
 {
 hgBotDelayNoWarn();  // delay but suppress warning at 10-20 sec delay level because this is not html output.
-char *fileName = cartUsualString(cart, hgtaOutFileName, "");
-// Don't allow '/' in fileName -- textOutInit interprets that as indicating a local file on disk
-subChar(fileName, '/', '_');
-// Don't allow ',' in fileName -- results in HTTP response header syntax error.
-subChar(fileName, ',', '.');
+char *fileName = textOutSanitizeHttpFileName(cartUsualString(cart, hgtaOutFileName, ""));
 char *compressType = cartUsualString(cart, hgtaCompressType,
 				     textOutCompressNone);
 
 if (doGenomeSpace())
     {
     char hgsid[64];
     struct tempName tn;
     safef(hgsid, sizeof(hgsid), "%s", cartSessionId(cart));
     trashDirFile(&tn, "genomeSpace", hgsid, ".tmp");
     gsTemp = cloneString(tn.forCgi);
     fileName = gsTemp;
     }
 
 compressPipeline = textOutInit(fileName, compressType, &saveStdout);
 }