Fossil SCM

Changing a setting to an empty string is now the same as unsetting that value, in most cases. Settings that are exceptions to the rule are marked with the "keep-empty" flag. Fix for the issue reported by [forum:/forumpost/a17b5fa51d607e3d|forum post a17b5fa51d607e3d].

drh 2023-09-28 14:13 trunk merge
Commit 1f6ae1efb4fcb222ec7007012af812bc1ec9b4d62a216bc3f3e8f9161c9b5f8e
+12 -2
--- src/db.c
+++ src/db.c
@@ -3728,11 +3728,21 @@
37283728
z = db_text(0, "SELECT strftime(%Q,%Q,'unixepoch');", zFormat, z);
37293729
}
37303730
return z;
37313731
}
37323732
void db_set(const char *zName, const char *zValue, int globalFlag){
3733
+ const CmdOrPage *pCmd = 0;
37333734
db_assert_protection_off_or_not_sensitive(zName);
3735
+ if( zValue!=0 && zValue[0]==0
3736
+ && dispatch_name_search(zName, CMDFLAG_SETTING, &pCmd)==0
3737
+ && (pCmd->eCmdFlags & CMDFLAG_KEEPEMPTY)==0
3738
+ ){
3739
+ /* Changing a setting to an empty string is the same as unsetting it,
3740
+ ** unless that setting has the keep-empty flag. */
3741
+ db_unset(zName/*works-like:"x"*/, globalFlag);
3742
+ return;
3743
+ }
37343744
db_unprotect(PROTECT_CONFIG);
37353745
db_begin_transaction();
37363746
if( globalFlag ){
37373747
db_swap_connections();
37383748
db_multi_exec("REPLACE INTO global_config(name,value) VALUES(%Q,%Q)",
@@ -4568,11 +4578,11 @@
45684578
/*
45694579
** SETTING: crnl-glob width=40 versionable block-text
45704580
** This is an alias for the crlf-glob setting.
45714581
*/
45724582
/*
4573
-** SETTING: default-perms width=16 default=u sensitive
4583
+** SETTING: default-perms width=16 default=u sensitive keep-empty
45744584
** Permissions given automatically to new users. For more
45754585
** information on permissions see the Users page in Server
45764586
** Administration of the HTTP UI.
45774587
*/
45784588
/*
@@ -4950,11 +4960,11 @@
49504960
** Specify which URI's are allowed in HTTP requests from
49514961
** TH1 scripts. If empty, no HTTP requests are allowed
49524962
** whatsoever.
49534963
*/
49544964
/*
4955
-** SETTING: default-csp width=40 block-text
4965
+** SETTING: default-csp width=40 block-text keep-empty
49564966
**
49574967
** The text of the Content Security Policy that is included
49584968
** in the Content-Security-Policy: header field of the HTTP
49594969
** reply and in the default HTML <head> section that is added when the
49604970
** skin header does not specify a <head> section. The text "$nonce"
49614971
--- src/db.c
+++ src/db.c
@@ -3728,11 +3728,21 @@
3728 z = db_text(0, "SELECT strftime(%Q,%Q,'unixepoch');", zFormat, z);
3729 }
3730 return z;
3731 }
3732 void db_set(const char *zName, const char *zValue, int globalFlag){
 
3733 db_assert_protection_off_or_not_sensitive(zName);
 
 
 
 
 
 
 
 
 
3734 db_unprotect(PROTECT_CONFIG);
3735 db_begin_transaction();
3736 if( globalFlag ){
3737 db_swap_connections();
3738 db_multi_exec("REPLACE INTO global_config(name,value) VALUES(%Q,%Q)",
@@ -4568,11 +4578,11 @@
4568 /*
4569 ** SETTING: crnl-glob width=40 versionable block-text
4570 ** This is an alias for the crlf-glob setting.
4571 */
4572 /*
4573 ** SETTING: default-perms width=16 default=u sensitive
4574 ** Permissions given automatically to new users. For more
4575 ** information on permissions see the Users page in Server
4576 ** Administration of the HTTP UI.
4577 */
4578 /*
@@ -4950,11 +4960,11 @@
4950 ** Specify which URI's are allowed in HTTP requests from
4951 ** TH1 scripts. If empty, no HTTP requests are allowed
4952 ** whatsoever.
4953 */
4954 /*
4955 ** SETTING: default-csp width=40 block-text
4956 **
4957 ** The text of the Content Security Policy that is included
4958 ** in the Content-Security-Policy: header field of the HTTP
4959 ** reply and in the default HTML <head> section that is added when the
4960 ** skin header does not specify a <head> section. The text "$nonce"
4961
--- src/db.c
+++ src/db.c
@@ -3728,11 +3728,21 @@
3728 z = db_text(0, "SELECT strftime(%Q,%Q,'unixepoch');", zFormat, z);
3729 }
3730 return z;
3731 }
3732 void db_set(const char *zName, const char *zValue, int globalFlag){
3733 const CmdOrPage *pCmd = 0;
3734 db_assert_protection_off_or_not_sensitive(zName);
3735 if( zValue!=0 && zValue[0]==0
3736 && dispatch_name_search(zName, CMDFLAG_SETTING, &pCmd)==0
3737 && (pCmd->eCmdFlags & CMDFLAG_KEEPEMPTY)==0
3738 ){
3739 /* Changing a setting to an empty string is the same as unsetting it,
3740 ** unless that setting has the keep-empty flag. */
3741 db_unset(zName/*works-like:"x"*/, globalFlag);
3742 return;
3743 }
3744 db_unprotect(PROTECT_CONFIG);
3745 db_begin_transaction();
3746 if( globalFlag ){
3747 db_swap_connections();
3748 db_multi_exec("REPLACE INTO global_config(name,value) VALUES(%Q,%Q)",
@@ -4568,11 +4578,11 @@
4578 /*
4579 ** SETTING: crnl-glob width=40 versionable block-text
4580 ** This is an alias for the crlf-glob setting.
4581 */
4582 /*
4583 ** SETTING: default-perms width=16 default=u sensitive keep-empty
4584 ** Permissions given automatically to new users. For more
4585 ** information on permissions see the Users page in Server
4586 ** Administration of the HTTP UI.
4587 */
4588 /*
@@ -4950,11 +4960,11 @@
4960 ** Specify which URI's are allowed in HTTP requests from
4961 ** TH1 scripts. If empty, no HTTP requests are allowed
4962 ** whatsoever.
4963 */
4964 /*
4965 ** SETTING: default-csp width=40 block-text keep-empty
4966 **
4967 ** The text of the Content Security Policy that is included
4968 ** in the Content-Security-Policy: header field of the HTTP
4969 ** reply and in the default HTML <head> section that is added when the
4970 ** skin header does not specify a <head> section. The text "$nonce"
4971
--- src/dispatch.c
+++ src/dispatch.c
@@ -53,10 +53,11 @@
5353
#define CMDFLAG_RAWCONTENT 0x0200 /* Do not interpret POST content */
5454
/* NOTE: 0x0400 = CMDFLAG_SENSITIVE in mkindex.c! */
5555
#define CMDFLAG_HIDDEN 0x0800 /* Elide from most listings */
5656
#define CMDFLAG_LDAVG_EXEMPT 0x1000 /* Exempt from load_control() */
5757
#define CMDFLAG_ALIAS 0x2000 /* Command aliases */
58
+#define CMDFLAG_KEEPEMPTY 0x4000 /* Do not unset empty settings */
5859
/**************************************************************************/
5960
6061
/* Values for the 2nd parameter to dispatch_name_search() */
6162
#define CMDFLAG_ANY 0x0038 /* Match anything */
6263
#define CMDFLAG_PREFIX 0x0200 /* Prefix match is ok */
6364
--- src/dispatch.c
+++ src/dispatch.c
@@ -53,10 +53,11 @@
53 #define CMDFLAG_RAWCONTENT 0x0200 /* Do not interpret POST content */
54 /* NOTE: 0x0400 = CMDFLAG_SENSITIVE in mkindex.c! */
55 #define CMDFLAG_HIDDEN 0x0800 /* Elide from most listings */
56 #define CMDFLAG_LDAVG_EXEMPT 0x1000 /* Exempt from load_control() */
57 #define CMDFLAG_ALIAS 0x2000 /* Command aliases */
 
58 /**************************************************************************/
59
60 /* Values for the 2nd parameter to dispatch_name_search() */
61 #define CMDFLAG_ANY 0x0038 /* Match anything */
62 #define CMDFLAG_PREFIX 0x0200 /* Prefix match is ok */
63
--- src/dispatch.c
+++ src/dispatch.c
@@ -53,10 +53,11 @@
53 #define CMDFLAG_RAWCONTENT 0x0200 /* Do not interpret POST content */
54 /* NOTE: 0x0400 = CMDFLAG_SENSITIVE in mkindex.c! */
55 #define CMDFLAG_HIDDEN 0x0800 /* Elide from most listings */
56 #define CMDFLAG_LDAVG_EXEMPT 0x1000 /* Exempt from load_control() */
57 #define CMDFLAG_ALIAS 0x2000 /* Command aliases */
58 #define CMDFLAG_KEEPEMPTY 0x4000 /* Do not unset empty settings */
59 /**************************************************************************/
60
61 /* Values for the 2nd parameter to dispatch_name_search() */
62 #define CMDFLAG_ANY 0x0038 /* Match anything */
63 #define CMDFLAG_PREFIX 0x0200 /* Prefix match is ok */
64
+1 -1
--- src/setup.c
+++ src/setup.c
@@ -1027,11 +1027,11 @@
10271027
db_end_transaction(0);
10281028
style_finish_page();
10291029
}
10301030
10311031
/*
1032
-** SETTING: mainmenu width=70 block-text
1032
+** SETTING: mainmenu width=70 block-text keep-empty
10331033
**
10341034
** The mainmenu setting specifies the entries on the main menu
10351035
** for many skins. The mainmenu should be a TCL list. Each set
10361036
** of four consecutive values defines a single main menu item:
10371037
**
10381038
--- src/setup.c
+++ src/setup.c
@@ -1027,11 +1027,11 @@
1027 db_end_transaction(0);
1028 style_finish_page();
1029 }
1030
1031 /*
1032 ** SETTING: mainmenu width=70 block-text
1033 **
1034 ** The mainmenu setting specifies the entries on the main menu
1035 ** for many skins. The mainmenu should be a TCL list. Each set
1036 ** of four consecutive values defines a single main menu item:
1037 **
1038
--- src/setup.c
+++ src/setup.c
@@ -1027,11 +1027,11 @@
1027 db_end_transaction(0);
1028 style_finish_page();
1029 }
1030
1031 /*
1032 ** SETTING: mainmenu width=70 block-text keep-empty
1033 **
1034 ** The mainmenu setting specifies the entries on the main menu
1035 ** for many skins. The mainmenu should be a TCL list. Each set
1036 ** of four consecutive values defines a single main menu item:
1037 **
1038
+3 -3
--- src/style.c
+++ src/style.c
@@ -608,12 +608,12 @@
608608
Blob csp;
609609
char *zNonce;
610610
char *zCsp;
611611
int i;
612612
if( disableCSP ) return fossil_strdup("");
613
- zFormat = db_get("default-csp","");
614
- if( zFormat[0]==0 ){
613
+ zFormat = db_get("default-csp",0);
614
+ if( zFormat==0 ){
615615
zFormat = zBackupCSP;
616616
}
617617
blob_init(&csp, 0, 0);
618618
while( zFormat[0] && (zNonce = strstr(zFormat,"$nonce"))!=0 ){
619619
blob_append(&csp, zFormat, (int)(zNonce - zFormat));
@@ -731,11 +731,11 @@
731731
** Returns the current mainmenu value from either the --mainmenu flag
732732
** (handled by the server/ui/cgi commands), the "mainmenu" config
733733
** setting, or style_default_mainmenu(), in that order, returning the
734734
** first of those which is defined.
735735
*/
736
-const char*style_get_mainmenu(){
736
+const char *style_get_mainmenu(){
737737
static const char *zMenu = 0;
738738
if(!zMenu){
739739
if(g.zMainMenuFile){
740740
Blob b = empty_blob;
741741
blob_read_from_file(&b, g.zMainMenuFile, ExtFILE);
742742
--- src/style.c
+++ src/style.c
@@ -608,12 +608,12 @@
608 Blob csp;
609 char *zNonce;
610 char *zCsp;
611 int i;
612 if( disableCSP ) return fossil_strdup("");
613 zFormat = db_get("default-csp","");
614 if( zFormat[0]==0 ){
615 zFormat = zBackupCSP;
616 }
617 blob_init(&csp, 0, 0);
618 while( zFormat[0] && (zNonce = strstr(zFormat,"$nonce"))!=0 ){
619 blob_append(&csp, zFormat, (int)(zNonce - zFormat));
@@ -731,11 +731,11 @@
731 ** Returns the current mainmenu value from either the --mainmenu flag
732 ** (handled by the server/ui/cgi commands), the "mainmenu" config
733 ** setting, or style_default_mainmenu(), in that order, returning the
734 ** first of those which is defined.
735 */
736 const char*style_get_mainmenu(){
737 static const char *zMenu = 0;
738 if(!zMenu){
739 if(g.zMainMenuFile){
740 Blob b = empty_blob;
741 blob_read_from_file(&b, g.zMainMenuFile, ExtFILE);
742
--- src/style.c
+++ src/style.c
@@ -608,12 +608,12 @@
608 Blob csp;
609 char *zNonce;
610 char *zCsp;
611 int i;
612 if( disableCSP ) return fossil_strdup("");
613 zFormat = db_get("default-csp",0);
614 if( zFormat==0 ){
615 zFormat = zBackupCSP;
616 }
617 blob_init(&csp, 0, 0);
618 while( zFormat[0] && (zNonce = strstr(zFormat,"$nonce"))!=0 ){
619 blob_append(&csp, zFormat, (int)(zNonce - zFormat));
@@ -731,11 +731,11 @@
731 ** Returns the current mainmenu value from either the --mainmenu flag
732 ** (handled by the server/ui/cgi commands), the "mainmenu" config
733 ** setting, or style_default_mainmenu(), in that order, returning the
734 ** first of those which is defined.
735 */
736 const char *style_get_mainmenu(){
737 static const char *zMenu = 0;
738 if(!zMenu){
739 if(g.zMainMenuFile){
740 Blob b = empty_blob;
741 blob_read_from_file(&b, g.zMainMenuFile, ExtFILE);
742
--- tools/mkindex.c
+++ tools/mkindex.c
@@ -99,10 +99,11 @@
9999
#define CMDFLAG_RAWCONTENT 0x0200 /* Do not interpret webpage content */
100100
#define CMDFLAG_SENSITIVE 0x0400 /* Security-sensitive setting */
101101
#define CMDFLAG_HIDDEN 0x0800 /* Elide from most listings */
102102
#define CMDFLAG_LDAVG_EXEMPT 0x1000 /* Exempt from load_control() */
103103
#define CMDFLAG_ALIAS 0x2000 /* Command aliases */
104
+#define CMDFLAG_KEEPEMPTY 0x4000 /* Do not unset empty settings */
104105
/**************************************************************************/
105106
106107
/*
107108
** Each entry looks like this:
108109
*/
@@ -263,10 +264,12 @@
263264
aEntry[nUsed].iWidth = 0;
264265
aEntry[nUsed].eType |= CMDFLAG_BOOLEAN;
265266
}else if( j==10 && strncmp(&zLine[i], "block-text", j)==0 ){
266267
aEntry[nUsed].eType &= ~(CMDFLAG_BOOLEAN);
267268
aEntry[nUsed].eType |= CMDFLAG_BLOCKTEXT;
269
+ }else if( j==10 && strncmp(&zLine[i], "keep-empty", j)==0 ){
270
+ aEntry[nUsed].eType |= CMDFLAG_KEEPEMPTY;
268271
}else if( j==11 && strncmp(&zLine[i], "versionable", j)==0 ){
269272
aEntry[nUsed].eType |= CMDFLAG_VERSIONABLE;
270273
}else if( j==9 && strncmp(&zLine[i], "sensitive", j)==0 ){
271274
aEntry[nUsed].eType |= CMDFLAG_SENSITIVE;
272275
}else if( j>6 && strncmp(&zLine[i], "width=", 6)==0 ){
273276
--- tools/mkindex.c
+++ tools/mkindex.c
@@ -99,10 +99,11 @@
99 #define CMDFLAG_RAWCONTENT 0x0200 /* Do not interpret webpage content */
100 #define CMDFLAG_SENSITIVE 0x0400 /* Security-sensitive setting */
101 #define CMDFLAG_HIDDEN 0x0800 /* Elide from most listings */
102 #define CMDFLAG_LDAVG_EXEMPT 0x1000 /* Exempt from load_control() */
103 #define CMDFLAG_ALIAS 0x2000 /* Command aliases */
 
104 /**************************************************************************/
105
106 /*
107 ** Each entry looks like this:
108 */
@@ -263,10 +264,12 @@
263 aEntry[nUsed].iWidth = 0;
264 aEntry[nUsed].eType |= CMDFLAG_BOOLEAN;
265 }else if( j==10 && strncmp(&zLine[i], "block-text", j)==0 ){
266 aEntry[nUsed].eType &= ~(CMDFLAG_BOOLEAN);
267 aEntry[nUsed].eType |= CMDFLAG_BLOCKTEXT;
 
 
268 }else if( j==11 && strncmp(&zLine[i], "versionable", j)==0 ){
269 aEntry[nUsed].eType |= CMDFLAG_VERSIONABLE;
270 }else if( j==9 && strncmp(&zLine[i], "sensitive", j)==0 ){
271 aEntry[nUsed].eType |= CMDFLAG_SENSITIVE;
272 }else if( j>6 && strncmp(&zLine[i], "width=", 6)==0 ){
273
--- tools/mkindex.c
+++ tools/mkindex.c
@@ -99,10 +99,11 @@
99 #define CMDFLAG_RAWCONTENT 0x0200 /* Do not interpret webpage content */
100 #define CMDFLAG_SENSITIVE 0x0400 /* Security-sensitive setting */
101 #define CMDFLAG_HIDDEN 0x0800 /* Elide from most listings */
102 #define CMDFLAG_LDAVG_EXEMPT 0x1000 /* Exempt from load_control() */
103 #define CMDFLAG_ALIAS 0x2000 /* Command aliases */
104 #define CMDFLAG_KEEPEMPTY 0x4000 /* Do not unset empty settings */
105 /**************************************************************************/
106
107 /*
108 ** Each entry looks like this:
109 */
@@ -263,10 +264,12 @@
264 aEntry[nUsed].iWidth = 0;
265 aEntry[nUsed].eType |= CMDFLAG_BOOLEAN;
266 }else if( j==10 && strncmp(&zLine[i], "block-text", j)==0 ){
267 aEntry[nUsed].eType &= ~(CMDFLAG_BOOLEAN);
268 aEntry[nUsed].eType |= CMDFLAG_BLOCKTEXT;
269 }else if( j==10 && strncmp(&zLine[i], "keep-empty", j)==0 ){
270 aEntry[nUsed].eType |= CMDFLAG_KEEPEMPTY;
271 }else if( j==11 && strncmp(&zLine[i], "versionable", j)==0 ){
272 aEntry[nUsed].eType |= CMDFLAG_VERSIONABLE;
273 }else if( j==9 && strncmp(&zLine[i], "sensitive", j)==0 ){
274 aEntry[nUsed].eType |= CMDFLAG_SENSITIVE;
275 }else if( j>6 && strncmp(&zLine[i], "width=", 6)==0 ){
276

Keyboard Shortcuts

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