8ed54eda44eba3788b50aba97a70080dad274e90 galt Fri Oct 7 18:27:15 2016 -0700 Added a useful comment about tricky textarea newlines. diff --git src/lib/cheapcgi.c src/lib/cheapcgi.c index b4fde00..ad4a545 100644 --- src/lib/cheapcgi.c +++ src/lib/cheapcgi.c @@ -1547,31 +1547,38 @@ { char buf[256]; cgiMakeHiddenVar(name, on ? "on" : "off"); safef(buf, sizeof(buf), "%s%s", cgiBooleanShadowPrefix(), name); cgiMakeHiddenVarWithExtra(buf, "1",BOOLSHAD_EXTRA); } void cgiMakeTextArea(char *varName, char *initialVal, int rowCount, int columnCount) /* Make a text area with area rowCount X columnCount and with text: intialVal */ { cgiMakeTextAreaDisableable(varName, initialVal, rowCount, columnCount, FALSE); } void cgiMakeTextAreaDisableable(char *varName, char *initialVal, int rowCount, int columnCount, boolean disabled) /* Make a text area that can be disabled. The area has rowCount X - * columnCount and with text: intialVal */ + * columnCount and with text: intialVal + * + * We found out the hard way be very careful with linefeeds and their encoding inside the text "initialVal". + * All browsers submit the textarea values with CR LF newlines. + * If there is a lone CR or LF, the browser will insert the missing partner to form a new CR LF pair. + * This can lead to exponential doubling of newline characters or their html entities, + * if one of CR or LF is encoded and the other is not. + */ { htmlPrintf("<TEXTAREA NAME='%s|attr|' ROWS=%d COLS=%d %s|none|>%s</TEXTAREA>", varName, rowCount, columnCount, disabled ? "DISABLED" : "", (initialVal != NULL ? initialVal : "")); } void cgiMakeOnKeypressTextVar(char *varName, char *initialVal, int charSize, char *script) /* Make a text control filled with initial value, with a (java)script * to execute every time a key is pressed. If charSize is zero it's * calculated from initialVal size. */ { if (initialVal == NULL) initialVal = ""; if (charSize == 0) charSize = strlen(initialVal);