2b30b55d6a5b71648296873b570b9d68b4901b6a
galt
Wed Feb 15 02:21:56 2017 -0800
CSP code cleanup. Using jsInlineF where needed for compact and efficient code, not using fixed-size local javascript strings which could overflow.
diff --git src/hg/lib/jsHelper.c src/hg/lib/jsHelper.c
index 0c2e34f..158d385 100644
--- src/hg/lib/jsHelper.c
+++ src/hg/lib/jsHelper.c
@@ -33,34 +33,31 @@
void jsInit()
/* If this is the first call, set window.onload to the operations
* performed upon loading a page and print supporting javascript.
* Currently this just sets the page vertical position if specified on
* CGI, and includes jsHelper.js.
* Subsequent calls do nothing, so this can be called many times. */
{
if (! jsInited)
{
// jsh_pageVertPos trick taken from
// http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html
puts("");
int pos = cgiOptionalInt("jsh_pageVertPos", 0);
if (pos > 0)
{
- char javascript[1024];
- safef(javascript, sizeof javascript,
- "window.onload = function () { window.scrollTo(0, %d); }", pos);
- jsInline(javascript);
+ jsInlineF("window.onload = function () { window.scrollTo(0, %d); }", pos);
}
jsInited = TRUE;
jsIncludeFile("jsHelper.js", NULL);
}
}
struct dyString *jsOnChangeStart()
/* Start up an onChange string */
{
struct dyString *dy = dyStringNew(1024);
return dy;
}
char *jsOnChangeEnd(struct dyString **pDy)
/* Finish up javascript onChange command. */
@@ -77,34 +74,31 @@
dyStringPrintf(dy, "[document.mainForm.%s.selectedIndex].value; ", var);
}
void jsTextCarryOver(struct dyString *dy, char *var)
/* Add statement to carry-over text item to dy. */
{
dyStringPrintf(dy,
"document.hiddenForm.%s.value=document.mainForm.%s.value; ",
var, var);
}
void jsTrackingVar(char *jsVar, char *val)
/* Emit a little Javascript to keep track of a variable.
* This helps especially with radio buttons. */
{
-char javascript[256];
-safef(javascript, sizeof javascript,
- "var %s='%s';\n", jsVar, val);
-jsInline(javascript);
+jsInlineF("var %s='%s';\n", jsVar, val);
}
void jsMakeTrackingRadioButtonExtraHtml(char *cgiVar, char *jsVar,
char *val, char *selVal, char *extraHtml)
/* Make a radio button with extra HTML attributes that also sets tracking variable
* in javascript. */
{
char id[256];
safef(id, sizeof id, "%s_%s", cgiVar, val);
hPrintf(". */
{
puts("");
}
void jsReloadOnBackButton(struct cart *cart)
/* Add some javascript to detect that the back button (or reload) has been pressed,
* and to resubmit in that case to redraw the page with the latest cart contents. */
// __detectback trick from
// http://siphon9.net/loune/2009/07/detecting-the-back-or-refresh-button-click/
// Yes, I know this along with every other inline