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].
Commit
1f6ae1efb4fcb222ec7007012af812bc1ec9b4d62a216bc3f3e8f9161c9b5f8e
Parent
19799565b7a8c9f…
5 files changed
+12
-2
+1
+1
-1
+3
-3
+3
M
src/db.c
+12
-2
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -3728,11 +3728,21 @@ | ||
| 3728 | 3728 | z = db_text(0, "SELECT strftime(%Q,%Q,'unixepoch');", zFormat, z); |
| 3729 | 3729 | } |
| 3730 | 3730 | return z; |
| 3731 | 3731 | } |
| 3732 | 3732 | void db_set(const char *zName, const char *zValue, int globalFlag){ |
| 3733 | + const CmdOrPage *pCmd = 0; | |
| 3733 | 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 | + } | |
| 3734 | 3744 | db_unprotect(PROTECT_CONFIG); |
| 3735 | 3745 | db_begin_transaction(); |
| 3736 | 3746 | if( globalFlag ){ |
| 3737 | 3747 | db_swap_connections(); |
| 3738 | 3748 | db_multi_exec("REPLACE INTO global_config(name,value) VALUES(%Q,%Q)", |
| @@ -4568,11 +4578,11 @@ | ||
| 4568 | 4578 | /* |
| 4569 | 4579 | ** SETTING: crnl-glob width=40 versionable block-text |
| 4570 | 4580 | ** This is an alias for the crlf-glob setting. |
| 4571 | 4581 | */ |
| 4572 | 4582 | /* |
| 4573 | -** SETTING: default-perms width=16 default=u sensitive | |
| 4583 | +** SETTING: default-perms width=16 default=u sensitive keep-empty | |
| 4574 | 4584 | ** Permissions given automatically to new users. For more |
| 4575 | 4585 | ** information on permissions see the Users page in Server |
| 4576 | 4586 | ** Administration of the HTTP UI. |
| 4577 | 4587 | */ |
| 4578 | 4588 | /* |
| @@ -4950,11 +4960,11 @@ | ||
| 4950 | 4960 | ** Specify which URI's are allowed in HTTP requests from |
| 4951 | 4961 | ** TH1 scripts. If empty, no HTTP requests are allowed |
| 4952 | 4962 | ** whatsoever. |
| 4953 | 4963 | */ |
| 4954 | 4964 | /* |
| 4955 | -** SETTING: default-csp width=40 block-text | |
| 4965 | +** SETTING: default-csp width=40 block-text keep-empty | |
| 4956 | 4966 | ** |
| 4957 | 4967 | ** The text of the Content Security Policy that is included |
| 4958 | 4968 | ** in the Content-Security-Policy: header field of the HTTP |
| 4959 | 4969 | ** reply and in the default HTML <head> section that is added when the |
| 4960 | 4970 | ** skin header does not specify a <head> section. The text "$nonce" |
| 4961 | 4971 |
| --- 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 |
+1
| --- src/dispatch.c | ||
| +++ src/dispatch.c | ||
| @@ -53,10 +53,11 @@ | ||
| 53 | 53 | #define CMDFLAG_RAWCONTENT 0x0200 /* Do not interpret POST content */ |
| 54 | 54 | /* NOTE: 0x0400 = CMDFLAG_SENSITIVE in mkindex.c! */ |
| 55 | 55 | #define CMDFLAG_HIDDEN 0x0800 /* Elide from most listings */ |
| 56 | 56 | #define CMDFLAG_LDAVG_EXEMPT 0x1000 /* Exempt from load_control() */ |
| 57 | 57 | #define CMDFLAG_ALIAS 0x2000 /* Command aliases */ |
| 58 | +#define CMDFLAG_KEEPEMPTY 0x4000 /* Do not unset empty settings */ | |
| 58 | 59 | /**************************************************************************/ |
| 59 | 60 | |
| 60 | 61 | /* Values for the 2nd parameter to dispatch_name_search() */ |
| 61 | 62 | #define CMDFLAG_ANY 0x0038 /* Match anything */ |
| 62 | 63 | #define CMDFLAG_PREFIX 0x0200 /* Prefix match is ok */ |
| 63 | 64 |
| --- 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 @@ | ||
| 1027 | 1027 | db_end_transaction(0); |
| 1028 | 1028 | style_finish_page(); |
| 1029 | 1029 | } |
| 1030 | 1030 | |
| 1031 | 1031 | /* |
| 1032 | -** SETTING: mainmenu width=70 block-text | |
| 1032 | +** SETTING: mainmenu width=70 block-text keep-empty | |
| 1033 | 1033 | ** |
| 1034 | 1034 | ** The mainmenu setting specifies the entries on the main menu |
| 1035 | 1035 | ** for many skins. The mainmenu should be a TCL list. Each set |
| 1036 | 1036 | ** of four consecutive values defines a single main menu item: |
| 1037 | 1037 | ** |
| 1038 | 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 |
| 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 @@ | ||
| 608 | 608 | Blob csp; |
| 609 | 609 | char *zNonce; |
| 610 | 610 | char *zCsp; |
| 611 | 611 | int i; |
| 612 | 612 | 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 ){ | |
| 615 | 615 | zFormat = zBackupCSP; |
| 616 | 616 | } |
| 617 | 617 | blob_init(&csp, 0, 0); |
| 618 | 618 | while( zFormat[0] && (zNonce = strstr(zFormat,"$nonce"))!=0 ){ |
| 619 | 619 | blob_append(&csp, zFormat, (int)(zNonce - zFormat)); |
| @@ -731,11 +731,11 @@ | ||
| 731 | 731 | ** Returns the current mainmenu value from either the --mainmenu flag |
| 732 | 732 | ** (handled by the server/ui/cgi commands), the "mainmenu" config |
| 733 | 733 | ** setting, or style_default_mainmenu(), in that order, returning the |
| 734 | 734 | ** first of those which is defined. |
| 735 | 735 | */ |
| 736 | -const char*style_get_mainmenu(){ | |
| 736 | +const char *style_get_mainmenu(){ | |
| 737 | 737 | static const char *zMenu = 0; |
| 738 | 738 | if(!zMenu){ |
| 739 | 739 | if(g.zMainMenuFile){ |
| 740 | 740 | Blob b = empty_blob; |
| 741 | 741 | blob_read_from_file(&b, g.zMainMenuFile, ExtFILE); |
| 742 | 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",""); |
| 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 |
+3
| --- tools/mkindex.c | ||
| +++ tools/mkindex.c | ||
| @@ -99,10 +99,11 @@ | ||
| 99 | 99 | #define CMDFLAG_RAWCONTENT 0x0200 /* Do not interpret webpage content */ |
| 100 | 100 | #define CMDFLAG_SENSITIVE 0x0400 /* Security-sensitive setting */ |
| 101 | 101 | #define CMDFLAG_HIDDEN 0x0800 /* Elide from most listings */ |
| 102 | 102 | #define CMDFLAG_LDAVG_EXEMPT 0x1000 /* Exempt from load_control() */ |
| 103 | 103 | #define CMDFLAG_ALIAS 0x2000 /* Command aliases */ |
| 104 | +#define CMDFLAG_KEEPEMPTY 0x4000 /* Do not unset empty settings */ | |
| 104 | 105 | /**************************************************************************/ |
| 105 | 106 | |
| 106 | 107 | /* |
| 107 | 108 | ** Each entry looks like this: |
| 108 | 109 | */ |
| @@ -263,10 +264,12 @@ | ||
| 263 | 264 | aEntry[nUsed].iWidth = 0; |
| 264 | 265 | aEntry[nUsed].eType |= CMDFLAG_BOOLEAN; |
| 265 | 266 | }else if( j==10 && strncmp(&zLine[i], "block-text", j)==0 ){ |
| 266 | 267 | aEntry[nUsed].eType &= ~(CMDFLAG_BOOLEAN); |
| 267 | 268 | aEntry[nUsed].eType |= CMDFLAG_BLOCKTEXT; |
| 269 | + }else if( j==10 && strncmp(&zLine[i], "keep-empty", j)==0 ){ | |
| 270 | + aEntry[nUsed].eType |= CMDFLAG_KEEPEMPTY; | |
| 268 | 271 | }else if( j==11 && strncmp(&zLine[i], "versionable", j)==0 ){ |
| 269 | 272 | aEntry[nUsed].eType |= CMDFLAG_VERSIONABLE; |
| 270 | 273 | }else if( j==9 && strncmp(&zLine[i], "sensitive", j)==0 ){ |
| 271 | 274 | aEntry[nUsed].eType |= CMDFLAG_SENSITIVE; |
| 272 | 275 | }else if( j>6 && strncmp(&zLine[i], "width=", 6)==0 ){ |
| 273 | 276 |
| --- 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 |