Fossil SCM

Centralized handling of the TH_INIT_NO_ENCODE (formerly NO_ESC) flag in sendText().

stephan 2020-09-13 21:23 pikchr-th
Commit b95861fb8a617db2dbd4b726b4caa6a905ee4268492f34564f949d071f80baf5
2 files changed +1 -1 +15 -11
--- src/pikchrshow.c
+++ src/pikchrshow.c
@@ -205,11 +205,11 @@
205205
const char * zOutfile = "-";
206206
const int fWithDiv = find_option("div",0,0)!=0;
207207
const int fTh1 = find_option("th",0,0)!=0;
208208
const int fNosvg = find_option("th-nosvg",0,0)!=0;
209209
int isErr = 0;
210
- u32 fThFlags = TH_INIT_DEFAULT | TH_INIT_NO_ESC
210
+ u32 fThFlags = TH_INIT_DEFAULT | TH_INIT_NO_ENCODE
211211
| (find_option("th-novar",0,0)!=0 ? TH_R2B_NO_VARS : 0);
212212
213213
Th_InitTraceLog()/*processes -th-trace flag*/;
214214
verify_all_options();
215215
if(g.argc>4){
216216
--- 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 @@
3131
#define TH_INIT_NEED_CONFIG ((u32)0x00000001) /* Open configuration first? */
3232
#define TH_INIT_FORCE_TCL ((u32)0x00000002) /* Force Tcl to be enabled? */
3333
#define TH_INIT_FORCE_RESET ((u32)0x00000004) /* Force TH1 commands re-added? */
3434
#define TH_INIT_FORCE_SETUP ((u32)0x00000008) /* Force eval of setup script? */
3535
#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. */
3737
#define TH_INIT_MASK ((u32)0x0000003F) /* All possible init flags. */
3838
3939
/*
4040
** Useful and/or "well-known" combinations of flag values.
4141
*/
@@ -310,15 +310,18 @@
310310
}
311311
}
312312
return zRc;
313313
}
314314
315
+/* See Th_SetOutputBlob() */
315316
static Blob * pThOut = 0;
316317
/*
317318
** Sets the th1-internal output-redirection blob and returns the
318319
** 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.
320323
*/
321324
Blob * Th_SetOutputBlob(Blob * pOut){
322325
Blob * tmp = pThOut;
323326
pThOut = pOut;
324327
return tmp;
@@ -326,19 +329,23 @@
326329
327330
/*
328331
** Send text to the appropriate output: If pOut is not NULL, it is
329332
** appended there, else to the console or to the CGI reply buffer.
330333
** 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.
332336
**
333337
** If pOut is NULL and the global pThOut is not then that blob
334338
** is used for output.
335339
*/
336340
static void sendText(Blob * pOut, const char *z, int n, int encode){
337341
if(0==pOut && pThOut!=0){
338342
pOut = pThOut;
339343
}
344
+ if(TH_INIT_NO_ENCODE & g.th1Flags){
345
+ encode = 0;
346
+ }
340347
if( enableOutput && n ){
341348
if( n<0 ) n = strlen(z);
342349
if( encode ){
343350
z = htmlize(z, n);
344351
n = strlen(z);
@@ -472,16 +479,14 @@
472479
void *pConvert,
473480
int argc,
474481
const char **argv,
475482
int *argl
476483
){
477
- unsigned int doEscape = (TH_INIT_NO_ESC & g.th1Flags)
478
- ? 0U : *(unsigned int*)pConvert;
479484
if( argc!=2 ){
480485
return Th_WrongNumArgs(interp, "puts STRING");
481486
}
482
- sendText(0,(char*)argv[1], argl[1], doEscape);
487
+ sendText(0,(char*)argv[1], argl[1], *(unsigned int*)pConvert);
483488
return TH_OK;
484489
}
485490
486491
/*
487492
** TH1 command: redirect URL ?withMethod?
@@ -2722,18 +2727,17 @@
27222727
** The TH1 scripts are contained within <th1>...</th1>.
27232728
** TH1 variables are $aaa or $<aaa>. The first form of
27242729
** variable is literal. The second is run through htmlize
27252730
** before being inserted.
27262731
**
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().
27302735
*/
27312736
int Th_Render(const char *z){
2732
- return Th_RenderToBlob(z, pThOut, 0);
2737
+ return Th_RenderToBlob(z, 0, 0);
27332738
}
2734
-
27352739
27362740
/*
27372741
** COMMAND: test-th-render
27382742
**
27392743
** Usage: %fossil test-th-render FILE
27402744
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button