Fossil SCM
Centralized handling of the TH_INIT_NO_ENCODE (formerly NO_ESC) flag in sendText().
Commit
b95861fb8a617db2dbd4b726b4caa6a905ee4268492f34564f949d071f80baf5
Parent
a5eaa0661eb21ba…
2 files changed
+1
-1
+15
-11
+1
-1
| --- src/pikchrshow.c | ||
| +++ src/pikchrshow.c | ||
| @@ -205,11 +205,11 @@ | ||
| 205 | 205 | const char * zOutfile = "-"; |
| 206 | 206 | const int fWithDiv = find_option("div",0,0)!=0; |
| 207 | 207 | const int fTh1 = find_option("th",0,0)!=0; |
| 208 | 208 | const int fNosvg = find_option("th-nosvg",0,0)!=0; |
| 209 | 209 | int isErr = 0; |
| 210 | - u32 fThFlags = TH_INIT_DEFAULT | TH_INIT_NO_ESC | |
| 210 | + u32 fThFlags = TH_INIT_DEFAULT | TH_INIT_NO_ENCODE | |
| 211 | 211 | | (find_option("th-novar",0,0)!=0 ? TH_R2B_NO_VARS : 0); |
| 212 | 212 | |
| 213 | 213 | Th_InitTraceLog()/*processes -th-trace flag*/; |
| 214 | 214 | verify_all_options(); |
| 215 | 215 | if(g.argc>4){ |
| 216 | 216 |
| --- src/pikchrshow.c | |
| +++ src/pikchrshow.c | |
| @@ -205,11 +205,11 @@ | |
| 205 | const char * zOutfile = "-"; |
| 206 | const int fWithDiv = find_option("div",0,0)!=0; |
| 207 | const int fTh1 = find_option("th",0,0)!=0; |
| 208 | const int fNosvg = find_option("th-nosvg",0,0)!=0; |
| 209 | int isErr = 0; |
| 210 | u32 fThFlags = TH_INIT_DEFAULT | TH_INIT_NO_ESC |
| 211 | | (find_option("th-novar",0,0)!=0 ? TH_R2B_NO_VARS : 0); |
| 212 | |
| 213 | Th_InitTraceLog()/*processes -th-trace flag*/; |
| 214 | verify_all_options(); |
| 215 | if(g.argc>4){ |
| 216 |
| --- src/pikchrshow.c | |
| +++ src/pikchrshow.c | |
| @@ -205,11 +205,11 @@ | |
| 205 | const char * zOutfile = "-"; |
| 206 | const int fWithDiv = find_option("div",0,0)!=0; |
| 207 | const int fTh1 = find_option("th",0,0)!=0; |
| 208 | const int fNosvg = find_option("th-nosvg",0,0)!=0; |
| 209 | int isErr = 0; |
| 210 | u32 fThFlags = TH_INIT_DEFAULT | TH_INIT_NO_ENCODE |
| 211 | | (find_option("th-novar",0,0)!=0 ? TH_R2B_NO_VARS : 0); |
| 212 | |
| 213 | Th_InitTraceLog()/*processes -th-trace flag*/; |
| 214 | verify_all_options(); |
| 215 | if(g.argc>4){ |
| 216 |
+15
-11
| --- src/th_main.c | ||
| +++ src/th_main.c | ||
| @@ -31,11 +31,11 @@ | ||
| 31 | 31 | #define TH_INIT_NEED_CONFIG ((u32)0x00000001) /* Open configuration first? */ |
| 32 | 32 | #define TH_INIT_FORCE_TCL ((u32)0x00000002) /* Force Tcl to be enabled? */ |
| 33 | 33 | #define TH_INIT_FORCE_RESET ((u32)0x00000004) /* Force TH1 commands re-added? */ |
| 34 | 34 | #define TH_INIT_FORCE_SETUP ((u32)0x00000008) /* Force eval of setup script? */ |
| 35 | 35 | #define TH_INIT_NO_REPO ((u32)0x00000010) /* Skip opening repository. */ |
| 36 | -#define TH_INIT_NO_ESC ((u32)0x00000020) /* Do not html-escape certain output. */ | |
| 36 | +#define TH_INIT_NO_ENCODE ((u32)0x00000020) /* Do not html-encode sentText() output. */ | |
| 37 | 37 | #define TH_INIT_MASK ((u32)0x0000003F) /* All possible init flags. */ |
| 38 | 38 | |
| 39 | 39 | /* |
| 40 | 40 | ** Useful and/or "well-known" combinations of flag values. |
| 41 | 41 | */ |
| @@ -310,15 +310,18 @@ | ||
| 310 | 310 | } |
| 311 | 311 | } |
| 312 | 312 | return zRc; |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | +/* See Th_SetOutputBlob() */ | |
| 315 | 316 | static Blob * pThOut = 0; |
| 316 | 317 | /* |
| 317 | 318 | ** Sets the th1-internal output-redirection blob and returns the |
| 318 | 319 | ** previous value. That blob is used by certain output-generation |
| 319 | -** routines to emit its output. | |
| 320 | +** routines to emit its output. It returns the previous value so that | |
| 321 | +** a routing can temporarily replace the buffer with its own and | |
| 322 | +** restore it when it's done. | |
| 320 | 323 | */ |
| 321 | 324 | Blob * Th_SetOutputBlob(Blob * pOut){ |
| 322 | 325 | Blob * tmp = pThOut; |
| 323 | 326 | pThOut = pOut; |
| 324 | 327 | return tmp; |
| @@ -326,19 +329,23 @@ | ||
| 326 | 329 | |
| 327 | 330 | /* |
| 328 | 331 | ** Send text to the appropriate output: If pOut is not NULL, it is |
| 329 | 332 | ** appended there, else to the console or to the CGI reply buffer. |
| 330 | 333 | ** Escape all characters with special meaning to HTML if the encode |
| 331 | -** parameter is true. | |
| 334 | +** parameter is true, with the exception that that flag is ignored if | |
| 335 | +** g.th1Flags has the TH_INIT_NO_ENCODE flag. | |
| 332 | 336 | ** |
| 333 | 337 | ** If pOut is NULL and the global pThOut is not then that blob |
| 334 | 338 | ** is used for output. |
| 335 | 339 | */ |
| 336 | 340 | static void sendText(Blob * pOut, const char *z, int n, int encode){ |
| 337 | 341 | if(0==pOut && pThOut!=0){ |
| 338 | 342 | pOut = pThOut; |
| 339 | 343 | } |
| 344 | + if(TH_INIT_NO_ENCODE & g.th1Flags){ | |
| 345 | + encode = 0; | |
| 346 | + } | |
| 340 | 347 | if( enableOutput && n ){ |
| 341 | 348 | if( n<0 ) n = strlen(z); |
| 342 | 349 | if( encode ){ |
| 343 | 350 | z = htmlize(z, n); |
| 344 | 351 | n = strlen(z); |
| @@ -472,16 +479,14 @@ | ||
| 472 | 479 | void *pConvert, |
| 473 | 480 | int argc, |
| 474 | 481 | const char **argv, |
| 475 | 482 | int *argl |
| 476 | 483 | ){ |
| 477 | - unsigned int doEscape = (TH_INIT_NO_ESC & g.th1Flags) | |
| 478 | - ? 0U : *(unsigned int*)pConvert; | |
| 479 | 484 | if( argc!=2 ){ |
| 480 | 485 | return Th_WrongNumArgs(interp, "puts STRING"); |
| 481 | 486 | } |
| 482 | - sendText(0,(char*)argv[1], argl[1], doEscape); | |
| 487 | + sendText(0,(char*)argv[1], argl[1], *(unsigned int*)pConvert); | |
| 483 | 488 | return TH_OK; |
| 484 | 489 | } |
| 485 | 490 | |
| 486 | 491 | /* |
| 487 | 492 | ** TH1 command: redirect URL ?withMethod? |
| @@ -2722,18 +2727,17 @@ | ||
| 2722 | 2727 | ** The TH1 scripts are contained within <th1>...</th1>. |
| 2723 | 2728 | ** TH1 variables are $aaa or $<aaa>. The first form of |
| 2724 | 2729 | ** variable is literal. The second is run through htmlize |
| 2725 | 2730 | ** before being inserted. |
| 2726 | 2731 | ** |
| 2727 | -** This routine processes the template and writes the results on | |
| 2728 | -** either stdout, into CGI, or to an internal blob which was set up | |
| 2729 | -** via a recursive call to this routine. | |
| 2732 | +** This routine processes the template and writes the results to one | |
| 2733 | +** of stdout, CGI, or an internal blob which was set up via a prior | |
| 2734 | +** call to Th_SetOutputBlob(). | |
| 2730 | 2735 | */ |
| 2731 | 2736 | int Th_Render(const char *z){ |
| 2732 | - return Th_RenderToBlob(z, pThOut, 0); | |
| 2737 | + return Th_RenderToBlob(z, 0, 0); | |
| 2733 | 2738 | } |
| 2734 | - | |
| 2735 | 2739 | |
| 2736 | 2740 | /* |
| 2737 | 2741 | ** COMMAND: test-th-render |
| 2738 | 2742 | ** |
| 2739 | 2743 | ** Usage: %fossil test-th-render FILE |
| 2740 | 2744 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -31,11 +31,11 @@ | |
| 31 | #define TH_INIT_NEED_CONFIG ((u32)0x00000001) /* Open configuration first? */ |
| 32 | #define TH_INIT_FORCE_TCL ((u32)0x00000002) /* Force Tcl to be enabled? */ |
| 33 | #define TH_INIT_FORCE_RESET ((u32)0x00000004) /* Force TH1 commands re-added? */ |
| 34 | #define TH_INIT_FORCE_SETUP ((u32)0x00000008) /* Force eval of setup script? */ |
| 35 | #define TH_INIT_NO_REPO ((u32)0x00000010) /* Skip opening repository. */ |
| 36 | #define TH_INIT_NO_ESC ((u32)0x00000020) /* Do not html-escape certain output. */ |
| 37 | #define TH_INIT_MASK ((u32)0x0000003F) /* All possible init flags. */ |
| 38 | |
| 39 | /* |
| 40 | ** Useful and/or "well-known" combinations of flag values. |
| 41 | */ |
| @@ -310,15 +310,18 @@ | |
| 310 | } |
| 311 | } |
| 312 | return zRc; |
| 313 | } |
| 314 | |
| 315 | static Blob * pThOut = 0; |
| 316 | /* |
| 317 | ** Sets the th1-internal output-redirection blob and returns the |
| 318 | ** previous value. That blob is used by certain output-generation |
| 319 | ** routines to emit its output. |
| 320 | */ |
| 321 | Blob * Th_SetOutputBlob(Blob * pOut){ |
| 322 | Blob * tmp = pThOut; |
| 323 | pThOut = pOut; |
| 324 | return tmp; |
| @@ -326,19 +329,23 @@ | |
| 326 | |
| 327 | /* |
| 328 | ** Send text to the appropriate output: If pOut is not NULL, it is |
| 329 | ** appended there, else to the console or to the CGI reply buffer. |
| 330 | ** Escape all characters with special meaning to HTML if the encode |
| 331 | ** parameter is true. |
| 332 | ** |
| 333 | ** If pOut is NULL and the global pThOut is not then that blob |
| 334 | ** is used for output. |
| 335 | */ |
| 336 | static void sendText(Blob * pOut, const char *z, int n, int encode){ |
| 337 | if(0==pOut && pThOut!=0){ |
| 338 | pOut = pThOut; |
| 339 | } |
| 340 | if( enableOutput && n ){ |
| 341 | if( n<0 ) n = strlen(z); |
| 342 | if( encode ){ |
| 343 | z = htmlize(z, n); |
| 344 | n = strlen(z); |
| @@ -472,16 +479,14 @@ | |
| 472 | void *pConvert, |
| 473 | int argc, |
| 474 | const char **argv, |
| 475 | int *argl |
| 476 | ){ |
| 477 | unsigned int doEscape = (TH_INIT_NO_ESC & g.th1Flags) |
| 478 | ? 0U : *(unsigned int*)pConvert; |
| 479 | if( argc!=2 ){ |
| 480 | return Th_WrongNumArgs(interp, "puts STRING"); |
| 481 | } |
| 482 | sendText(0,(char*)argv[1], argl[1], doEscape); |
| 483 | return TH_OK; |
| 484 | } |
| 485 | |
| 486 | /* |
| 487 | ** TH1 command: redirect URL ?withMethod? |
| @@ -2722,18 +2727,17 @@ | |
| 2722 | ** The TH1 scripts are contained within <th1>...</th1>. |
| 2723 | ** TH1 variables are $aaa or $<aaa>. The first form of |
| 2724 | ** variable is literal. The second is run through htmlize |
| 2725 | ** before being inserted. |
| 2726 | ** |
| 2727 | ** This routine processes the template and writes the results on |
| 2728 | ** either stdout, into CGI, or to an internal blob which was set up |
| 2729 | ** via a recursive call to this routine. |
| 2730 | */ |
| 2731 | int Th_Render(const char *z){ |
| 2732 | return Th_RenderToBlob(z, pThOut, 0); |
| 2733 | } |
| 2734 | |
| 2735 | |
| 2736 | /* |
| 2737 | ** COMMAND: test-th-render |
| 2738 | ** |
| 2739 | ** Usage: %fossil test-th-render FILE |
| 2740 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -31,11 +31,11 @@ | |
| 31 | #define TH_INIT_NEED_CONFIG ((u32)0x00000001) /* Open configuration first? */ |
| 32 | #define TH_INIT_FORCE_TCL ((u32)0x00000002) /* Force Tcl to be enabled? */ |
| 33 | #define TH_INIT_FORCE_RESET ((u32)0x00000004) /* Force TH1 commands re-added? */ |
| 34 | #define TH_INIT_FORCE_SETUP ((u32)0x00000008) /* Force eval of setup script? */ |
| 35 | #define TH_INIT_NO_REPO ((u32)0x00000010) /* Skip opening repository. */ |
| 36 | #define TH_INIT_NO_ENCODE ((u32)0x00000020) /* Do not html-encode sentText() output. */ |
| 37 | #define TH_INIT_MASK ((u32)0x0000003F) /* All possible init flags. */ |
| 38 | |
| 39 | /* |
| 40 | ** Useful and/or "well-known" combinations of flag values. |
| 41 | */ |
| @@ -310,15 +310,18 @@ | |
| 310 | } |
| 311 | } |
| 312 | return zRc; |
| 313 | } |
| 314 | |
| 315 | /* See Th_SetOutputBlob() */ |
| 316 | static Blob * pThOut = 0; |
| 317 | /* |
| 318 | ** Sets the th1-internal output-redirection blob and returns the |
| 319 | ** previous value. That blob is used by certain output-generation |
| 320 | ** routines to emit its output. It returns the previous value so that |
| 321 | ** a routing can temporarily replace the buffer with its own and |
| 322 | ** restore it when it's done. |
| 323 | */ |
| 324 | Blob * Th_SetOutputBlob(Blob * pOut){ |
| 325 | Blob * tmp = pThOut; |
| 326 | pThOut = pOut; |
| 327 | return tmp; |
| @@ -326,19 +329,23 @@ | |
| 329 | |
| 330 | /* |
| 331 | ** Send text to the appropriate output: If pOut is not NULL, it is |
| 332 | ** appended there, else to the console or to the CGI reply buffer. |
| 333 | ** Escape all characters with special meaning to HTML if the encode |
| 334 | ** parameter is true, with the exception that that flag is ignored if |
| 335 | ** g.th1Flags has the TH_INIT_NO_ENCODE flag. |
| 336 | ** |
| 337 | ** If pOut is NULL and the global pThOut is not then that blob |
| 338 | ** is used for output. |
| 339 | */ |
| 340 | static void sendText(Blob * pOut, const char *z, int n, int encode){ |
| 341 | if(0==pOut && pThOut!=0){ |
| 342 | pOut = pThOut; |
| 343 | } |
| 344 | if(TH_INIT_NO_ENCODE & g.th1Flags){ |
| 345 | encode = 0; |
| 346 | } |
| 347 | if( enableOutput && n ){ |
| 348 | if( n<0 ) n = strlen(z); |
| 349 | if( encode ){ |
| 350 | z = htmlize(z, n); |
| 351 | n = strlen(z); |
| @@ -472,16 +479,14 @@ | |
| 479 | void *pConvert, |
| 480 | int argc, |
| 481 | const char **argv, |
| 482 | int *argl |
| 483 | ){ |
| 484 | if( argc!=2 ){ |
| 485 | return Th_WrongNumArgs(interp, "puts STRING"); |
| 486 | } |
| 487 | sendText(0,(char*)argv[1], argl[1], *(unsigned int*)pConvert); |
| 488 | return TH_OK; |
| 489 | } |
| 490 | |
| 491 | /* |
| 492 | ** TH1 command: redirect URL ?withMethod? |
| @@ -2722,18 +2727,17 @@ | |
| 2727 | ** The TH1 scripts are contained within <th1>...</th1>. |
| 2728 | ** TH1 variables are $aaa or $<aaa>. The first form of |
| 2729 | ** variable is literal. The second is run through htmlize |
| 2730 | ** before being inserted. |
| 2731 | ** |
| 2732 | ** This routine processes the template and writes the results to one |
| 2733 | ** of stdout, CGI, or an internal blob which was set up via a prior |
| 2734 | ** call to Th_SetOutputBlob(). |
| 2735 | */ |
| 2736 | int Th_Render(const char *z){ |
| 2737 | return Th_RenderToBlob(z, 0, 0); |
| 2738 | } |
| 2739 | |
| 2740 | /* |
| 2741 | ** COMMAND: test-th-render |
| 2742 | ** |
| 2743 | ** Usage: %fossil test-th-render FILE |
| 2744 |