Fossil SCM
Sanitize the mimetypes on both the CLI and json. Allow more friendly names for the supported mimetypes as well as the formal mimetypes
dave.vines
2016-04-18 19:18
Commit
7ed9c7e4a9eae1d8fec14fb33e6b01f9ebaa97f2
Parent
70131d08e27bf47…
2 files changed
+1
+22
-15
+1
| --- src/json_wiki.c | ||
| +++ src/json_wiki.c | ||
| @@ -374,10 +374,11 @@ | ||
| 374 | 374 | if(contentLen){ |
| 375 | 375 | blob_append(&content, cson_string_cstr(jstr),contentLen); |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | zMimeType = json_find_option_cstr("mimetype","mimetype","M"); |
| 379 | + zMimeType = wiki_filter_mimetypes(zMimeType); | |
| 379 | 380 | |
| 380 | 381 | wiki_cmd_commit(zPageName, rid, &content, zMimeType, 0); |
| 381 | 382 | blob_reset(&content); |
| 382 | 383 | /* |
| 383 | 384 | Our return value here has a race condition: if this operation |
| 384 | 385 |
| --- src/json_wiki.c | |
| +++ src/json_wiki.c | |
| @@ -374,10 +374,11 @@ | |
| 374 | if(contentLen){ |
| 375 | blob_append(&content, cson_string_cstr(jstr),contentLen); |
| 376 | } |
| 377 | |
| 378 | zMimeType = json_find_option_cstr("mimetype","mimetype","M"); |
| 379 | |
| 380 | wiki_cmd_commit(zPageName, rid, &content, zMimeType, 0); |
| 381 | blob_reset(&content); |
| 382 | /* |
| 383 | Our return value here has a race condition: if this operation |
| 384 |
| --- src/json_wiki.c | |
| +++ src/json_wiki.c | |
| @@ -374,10 +374,11 @@ | |
| 374 | if(contentLen){ |
| 375 | blob_append(&content, cson_string_cstr(jstr),contentLen); |
| 376 | } |
| 377 | |
| 378 | zMimeType = json_find_option_cstr("mimetype","mimetype","M"); |
| 379 | zMimeType = wiki_filter_mimetypes(zMimeType); |
| 380 | |
| 381 | wiki_cmd_commit(zPageName, rid, &content, zMimeType, 0); |
| 382 | blob_reset(&content); |
| 383 | /* |
| 384 | Our return value here has a race condition: if this operation |
| 385 |
+22
-15
| --- src/wiki.c | ||
| +++ src/wiki.c | ||
| @@ -122,20 +122,34 @@ | ||
| 122 | 122 | static int is_sandbox(const char *zPagename){ |
| 123 | 123 | return fossil_stricmp(zPagename,"sandbox")==0 || |
| 124 | 124 | fossil_stricmp(zPagename,"sand box")==0; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | +/* | |
| 128 | +** Formal, common and short names for the various wiki styles. | |
| 129 | +*/ | |
| 130 | +static const char *const azStyles[] = { | |
| 131 | + "text/x-fossil-wiki", "Fossil Wiki", "wiki", | |
| 132 | + "text/x-markdown", "Markdown", "markdown", | |
| 133 | + "text/plain", "Plain Text", "plain" | |
| 134 | +}; | |
| 135 | + | |
| 127 | 136 | /* |
| 128 | 137 | ** Only allow certain mimetypes through. |
| 129 | 138 | ** All others become "text/x-fossil-wiki" |
| 130 | 139 | */ |
| 131 | 140 | const char *wiki_filter_mimetypes(const char *zMimetype){ |
| 132 | - if( zMimetype!=0 && | |
| 133 | - ( fossil_strcmp(zMimetype, "text/x-markdown")==0 | |
| 134 | - || fossil_strcmp(zMimetype, "text/plain")==0 ) | |
| 135 | - ){ | |
| 136 | - return zMimetype; | |
| 141 | + if( zMimetype!=0 ){ | |
| 142 | + for(int i=0; i<sizeof(azStyles)/sizeof(azStyles[0]); i+=3){ | |
| 143 | + if( fossil_strcmp(zMimetype,azStyles[i+2])==0 ){ | |
| 144 | + return azStyles[i]; | |
| 145 | + } | |
| 146 | + } | |
| 147 | + if( fossil_strcmp(zMimetype, "text/x-markdown")==0 | |
| 148 | + || fossil_strcmp(zMimetype, "text/plain")==0 ){ | |
| 149 | + return zMimetype; | |
| 150 | + } | |
| 137 | 151 | } |
| 138 | 152 | return "text/x-fossil-wiki"; |
| 139 | 153 | } |
| 140 | 154 | |
| 141 | 155 | /* |
| @@ -412,27 +426,18 @@ | ||
| 412 | 426 | db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nrid); |
| 413 | 427 | db_multi_exec("INSERT OR IGNORE INTO unclustered VALUES(%d);", nrid); |
| 414 | 428 | manifest_crosslink(nrid, pWiki, MC_NONE); |
| 415 | 429 | } |
| 416 | 430 | |
| 417 | -/* | |
| 418 | -** Formal names and common names for the various wiki styles. | |
| 419 | -*/ | |
| 420 | -static const char *const azStyles[] = { | |
| 421 | - "text/x-fossil-wiki", "Fossil Wiki", | |
| 422 | - "text/x-markdown", "Markdown", | |
| 423 | - "text/plain", "Plain Text" | |
| 424 | -}; | |
| 425 | - | |
| 426 | 431 | /* |
| 427 | 432 | ** Output a selection box from which the user can select the |
| 428 | 433 | ** wiki mimetype. |
| 429 | 434 | */ |
| 430 | 435 | void mimetype_option_menu(const char *zMimetype){ |
| 431 | 436 | unsigned i; |
| 432 | 437 | @ <select name="mimetype" size="1"> |
| 433 | - for(i=0; i<sizeof(azStyles)/sizeof(azStyles[0]); i+=2){ | |
| 438 | + for(i=0; i<sizeof(azStyles)/sizeof(azStyles[0]); i+=3){ | |
| 434 | 439 | if( fossil_strcmp(zMimetype,azStyles[i])==0 ){ |
| 435 | 440 | @ <option value="%s(azStyles[i])" selected>%s(azStyles[i+1])</option> |
| 436 | 441 | }else{ |
| 437 | 442 | @ <option value="%s(azStyles[i])">%s(azStyles[i+1])</option> |
| 438 | 443 | } |
| @@ -1314,10 +1319,12 @@ | ||
| 1314 | 1319 | if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 |
| 1315 | 1320 | && (pWiki->zMimetype && *pWiki->zMimetype)){ |
| 1316 | 1321 | zMimeType = pWiki->zMimetype; |
| 1317 | 1322 | } |
| 1318 | 1323 | } |
| 1324 | + }else{ | |
| 1325 | + zMimeType = wiki_filter_mimetypes(zMimeType); | |
| 1319 | 1326 | } |
| 1320 | 1327 | if( g.argv[2][1]=='r' && rid>0 ){ |
| 1321 | 1328 | if ( !zETime ){ |
| 1322 | 1329 | fossil_fatal("wiki page %s already exists", zPageName); |
| 1323 | 1330 | }else{ |
| 1324 | 1331 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -122,20 +122,34 @@ | |
| 122 | static int is_sandbox(const char *zPagename){ |
| 123 | return fossil_stricmp(zPagename,"sandbox")==0 || |
| 124 | fossil_stricmp(zPagename,"sand box")==0; |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | ** Only allow certain mimetypes through. |
| 129 | ** All others become "text/x-fossil-wiki" |
| 130 | */ |
| 131 | const char *wiki_filter_mimetypes(const char *zMimetype){ |
| 132 | if( zMimetype!=0 && |
| 133 | ( fossil_strcmp(zMimetype, "text/x-markdown")==0 |
| 134 | || fossil_strcmp(zMimetype, "text/plain")==0 ) |
| 135 | ){ |
| 136 | return zMimetype; |
| 137 | } |
| 138 | return "text/x-fossil-wiki"; |
| 139 | } |
| 140 | |
| 141 | /* |
| @@ -412,27 +426,18 @@ | |
| 412 | db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nrid); |
| 413 | db_multi_exec("INSERT OR IGNORE INTO unclustered VALUES(%d);", nrid); |
| 414 | manifest_crosslink(nrid, pWiki, MC_NONE); |
| 415 | } |
| 416 | |
| 417 | /* |
| 418 | ** Formal names and common names for the various wiki styles. |
| 419 | */ |
| 420 | static const char *const azStyles[] = { |
| 421 | "text/x-fossil-wiki", "Fossil Wiki", |
| 422 | "text/x-markdown", "Markdown", |
| 423 | "text/plain", "Plain Text" |
| 424 | }; |
| 425 | |
| 426 | /* |
| 427 | ** Output a selection box from which the user can select the |
| 428 | ** wiki mimetype. |
| 429 | */ |
| 430 | void mimetype_option_menu(const char *zMimetype){ |
| 431 | unsigned i; |
| 432 | @ <select name="mimetype" size="1"> |
| 433 | for(i=0; i<sizeof(azStyles)/sizeof(azStyles[0]); i+=2){ |
| 434 | if( fossil_strcmp(zMimetype,azStyles[i])==0 ){ |
| 435 | @ <option value="%s(azStyles[i])" selected>%s(azStyles[i+1])</option> |
| 436 | }else{ |
| 437 | @ <option value="%s(azStyles[i])">%s(azStyles[i+1])</option> |
| 438 | } |
| @@ -1314,10 +1319,12 @@ | |
| 1314 | if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 |
| 1315 | && (pWiki->zMimetype && *pWiki->zMimetype)){ |
| 1316 | zMimeType = pWiki->zMimetype; |
| 1317 | } |
| 1318 | } |
| 1319 | } |
| 1320 | if( g.argv[2][1]=='r' && rid>0 ){ |
| 1321 | if ( !zETime ){ |
| 1322 | fossil_fatal("wiki page %s already exists", zPageName); |
| 1323 | }else{ |
| 1324 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -122,20 +122,34 @@ | |
| 122 | static int is_sandbox(const char *zPagename){ |
| 123 | return fossil_stricmp(zPagename,"sandbox")==0 || |
| 124 | fossil_stricmp(zPagename,"sand box")==0; |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | ** Formal, common and short names for the various wiki styles. |
| 129 | */ |
| 130 | static const char *const azStyles[] = { |
| 131 | "text/x-fossil-wiki", "Fossil Wiki", "wiki", |
| 132 | "text/x-markdown", "Markdown", "markdown", |
| 133 | "text/plain", "Plain Text", "plain" |
| 134 | }; |
| 135 | |
| 136 | /* |
| 137 | ** Only allow certain mimetypes through. |
| 138 | ** All others become "text/x-fossil-wiki" |
| 139 | */ |
| 140 | const char *wiki_filter_mimetypes(const char *zMimetype){ |
| 141 | if( zMimetype!=0 ){ |
| 142 | for(int i=0; i<sizeof(azStyles)/sizeof(azStyles[0]); i+=3){ |
| 143 | if( fossil_strcmp(zMimetype,azStyles[i+2])==0 ){ |
| 144 | return azStyles[i]; |
| 145 | } |
| 146 | } |
| 147 | if( fossil_strcmp(zMimetype, "text/x-markdown")==0 |
| 148 | || fossil_strcmp(zMimetype, "text/plain")==0 ){ |
| 149 | return zMimetype; |
| 150 | } |
| 151 | } |
| 152 | return "text/x-fossil-wiki"; |
| 153 | } |
| 154 | |
| 155 | /* |
| @@ -412,27 +426,18 @@ | |
| 426 | db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nrid); |
| 427 | db_multi_exec("INSERT OR IGNORE INTO unclustered VALUES(%d);", nrid); |
| 428 | manifest_crosslink(nrid, pWiki, MC_NONE); |
| 429 | } |
| 430 | |
| 431 | /* |
| 432 | ** Output a selection box from which the user can select the |
| 433 | ** wiki mimetype. |
| 434 | */ |
| 435 | void mimetype_option_menu(const char *zMimetype){ |
| 436 | unsigned i; |
| 437 | @ <select name="mimetype" size="1"> |
| 438 | for(i=0; i<sizeof(azStyles)/sizeof(azStyles[0]); i+=3){ |
| 439 | if( fossil_strcmp(zMimetype,azStyles[i])==0 ){ |
| 440 | @ <option value="%s(azStyles[i])" selected>%s(azStyles[i+1])</option> |
| 441 | }else{ |
| 442 | @ <option value="%s(azStyles[i])">%s(azStyles[i+1])</option> |
| 443 | } |
| @@ -1314,10 +1319,12 @@ | |
| 1319 | if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 |
| 1320 | && (pWiki->zMimetype && *pWiki->zMimetype)){ |
| 1321 | zMimeType = pWiki->zMimetype; |
| 1322 | } |
| 1323 | } |
| 1324 | }else{ |
| 1325 | zMimeType = wiki_filter_mimetypes(zMimeType); |
| 1326 | } |
| 1327 | if( g.argv[2][1]=='r' && rid>0 ){ |
| 1328 | if ( !zETime ){ |
| 1329 | fossil_fatal("wiki page %s already exists", zPageName); |
| 1330 | }else{ |
| 1331 |