Fossil SCM
Make sure the TH1 interp is available before trying to use it.
Commit
600accbec3aeff10fee269a0957cf68c8f81e19f6fb0badd088f87b54b8a2d20
Parent
68e6b07ebaf1ba6…
2 files changed
+6
-8
+14
+6
-8
| --- src/style.c | ||
| +++ src/style.c | ||
| @@ -410,18 +410,16 @@ | ||
| 410 | 410 | /* |
| 411 | 411 | ** Do not overwrite the TH1 variable "default_csp" if it exists, as this |
| 412 | 412 | ** allows it to be properly overridden via the TH1 setup script (i.e. it |
| 413 | 413 | ** is evaluated before the header is rendered). |
| 414 | 414 | */ |
| 415 | - if( !Th_ExistsVar(g.interp, "default_csp", -1) ){ | |
| 416 | - char *zDfltCsp = sqlite3_mprintf("default-src 'self' data: ; " | |
| 417 | - "script-src 'self' 'nonce-%s' ; " | |
| 418 | - "style-src 'self' 'unsafe-inline'", | |
| 419 | - zNonce); | |
| 420 | - Th_Store("default_csp", zDfltCsp); | |
| 421 | - sqlite3_free(zDfltCsp); | |
| 422 | - } | |
| 415 | + char *zDfltCsp = sqlite3_mprintf("default-src 'self' data: ; " | |
| 416 | + "script-src 'self' 'nonce-%s' ; " | |
| 417 | + "style-src 'self' 'unsafe-inline'", | |
| 418 | + zNonce); | |
| 419 | + Th_MaybeStore("default_csp", zDfltCsp); | |
| 420 | + sqlite3_free(zDfltCsp); | |
| 423 | 421 | Th_Store("nonce", zNonce); |
| 424 | 422 | Th_Store("project_name", db_get("project-name","Unnamed Fossil Project")); |
| 425 | 423 | Th_Store("project_description", db_get("project-description","")); |
| 426 | 424 | if( zTitle ) Th_Store("title", zTitle); |
| 427 | 425 | Th_Store("baseurl", g.zBaseURL); |
| 428 | 426 |
| --- src/style.c | |
| +++ src/style.c | |
| @@ -410,18 +410,16 @@ | |
| 410 | /* |
| 411 | ** Do not overwrite the TH1 variable "default_csp" if it exists, as this |
| 412 | ** allows it to be properly overridden via the TH1 setup script (i.e. it |
| 413 | ** is evaluated before the header is rendered). |
| 414 | */ |
| 415 | if( !Th_ExistsVar(g.interp, "default_csp", -1) ){ |
| 416 | char *zDfltCsp = sqlite3_mprintf("default-src 'self' data: ; " |
| 417 | "script-src 'self' 'nonce-%s' ; " |
| 418 | "style-src 'self' 'unsafe-inline'", |
| 419 | zNonce); |
| 420 | Th_Store("default_csp", zDfltCsp); |
| 421 | sqlite3_free(zDfltCsp); |
| 422 | } |
| 423 | Th_Store("nonce", zNonce); |
| 424 | Th_Store("project_name", db_get("project-name","Unnamed Fossil Project")); |
| 425 | Th_Store("project_description", db_get("project-description","")); |
| 426 | if( zTitle ) Th_Store("title", zTitle); |
| 427 | Th_Store("baseurl", g.zBaseURL); |
| 428 |
| --- src/style.c | |
| +++ src/style.c | |
| @@ -410,18 +410,16 @@ | |
| 410 | /* |
| 411 | ** Do not overwrite the TH1 variable "default_csp" if it exists, as this |
| 412 | ** allows it to be properly overridden via the TH1 setup script (i.e. it |
| 413 | ** is evaluated before the header is rendered). |
| 414 | */ |
| 415 | char *zDfltCsp = sqlite3_mprintf("default-src 'self' data: ; " |
| 416 | "script-src 'self' 'nonce-%s' ; " |
| 417 | "style-src 'self' 'unsafe-inline'", |
| 418 | zNonce); |
| 419 | Th_MaybeStore("default_csp", zDfltCsp); |
| 420 | sqlite3_free(zDfltCsp); |
| 421 | Th_Store("nonce", zNonce); |
| 422 | Th_Store("project_name", db_get("project-name","Unnamed Fossil Project")); |
| 423 | Th_Store("project_description", db_get("project-description","")); |
| 424 | if( zTitle ) Th_Store("title", zTitle); |
| 425 | Th_Store("baseurl", g.zBaseURL); |
| 426 |
+14
| --- src/th_main.c | ||
| +++ src/th_main.c | ||
| @@ -2125,10 +2125,24 @@ | ||
| 2125 | 2125 | } |
| 2126 | 2126 | } |
| 2127 | 2127 | g.th1Flags &= ~TH_INIT_MASK; |
| 2128 | 2128 | g.th1Flags |= (flags & TH_INIT_MASK); |
| 2129 | 2129 | } |
| 2130 | + | |
| 2131 | +/* | |
| 2132 | +** Store a string value in a variable in the interpreter if the variable | |
| 2133 | +** does not already exist. | |
| 2134 | +*/ | |
| 2135 | +void Th_MaybeStore(const char *zName, const char *zValue){ | |
| 2136 | + Th_FossilInit(TH_INIT_DEFAULT); | |
| 2137 | + if( zValue && !Th_ExistsVar(g.interp, zName, -1) ){ | |
| 2138 | + if( g.thTrace ){ | |
| 2139 | + Th_Trace("maybe_set %h {%h}<br />\n", zName, zValue); | |
| 2140 | + } | |
| 2141 | + Th_SetVar(g.interp, zName, -1, zValue, strlen(zValue)); | |
| 2142 | + } | |
| 2143 | +} | |
| 2130 | 2144 | |
| 2131 | 2145 | /* |
| 2132 | 2146 | ** Store a string value in a variable in the interpreter. |
| 2133 | 2147 | */ |
| 2134 | 2148 | void Th_Store(const char *zName, const char *zValue){ |
| 2135 | 2149 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -2125,10 +2125,24 @@ | |
| 2125 | } |
| 2126 | } |
| 2127 | g.th1Flags &= ~TH_INIT_MASK; |
| 2128 | g.th1Flags |= (flags & TH_INIT_MASK); |
| 2129 | } |
| 2130 | |
| 2131 | /* |
| 2132 | ** Store a string value in a variable in the interpreter. |
| 2133 | */ |
| 2134 | void Th_Store(const char *zName, const char *zValue){ |
| 2135 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -2125,10 +2125,24 @@ | |
| 2125 | } |
| 2126 | } |
| 2127 | g.th1Flags &= ~TH_INIT_MASK; |
| 2128 | g.th1Flags |= (flags & TH_INIT_MASK); |
| 2129 | } |
| 2130 | |
| 2131 | /* |
| 2132 | ** Store a string value in a variable in the interpreter if the variable |
| 2133 | ** does not already exist. |
| 2134 | */ |
| 2135 | void Th_MaybeStore(const char *zName, const char *zValue){ |
| 2136 | Th_FossilInit(TH_INIT_DEFAULT); |
| 2137 | if( zValue && !Th_ExistsVar(g.interp, zName, -1) ){ |
| 2138 | if( g.thTrace ){ |
| 2139 | Th_Trace("maybe_set %h {%h}<br />\n", zName, zValue); |
| 2140 | } |
| 2141 | Th_SetVar(g.interp, zName, -1, zValue, strlen(zValue)); |
| 2142 | } |
| 2143 | } |
| 2144 | |
| 2145 | /* |
| 2146 | ** Store a string value in a variable in the interpreter. |
| 2147 | */ |
| 2148 | void Th_Store(const char *zName, const char *zValue){ |
| 2149 |