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
2 files changed +1 +22 -15
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -374,10 +374,11 @@
374374
if(contentLen){
375375
blob_append(&content, cson_string_cstr(jstr),contentLen);
376376
}
377377
378378
zMimeType = json_find_option_cstr("mimetype","mimetype","M");
379
+ zMimeType = wiki_filter_mimetypes(zMimeType);
379380
380381
wiki_cmd_commit(zPageName, rid, &content, zMimeType, 0);
381382
blob_reset(&content);
382383
/*
383384
Our return value here has a race condition: if this operation
384385
--- 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 @@
122122
static int is_sandbox(const char *zPagename){
123123
return fossil_stricmp(zPagename,"sandbox")==0 ||
124124
fossil_stricmp(zPagename,"sand box")==0;
125125
}
126126
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
+
127136
/*
128137
** Only allow certain mimetypes through.
129138
** All others become "text/x-fossil-wiki"
130139
*/
131140
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
+ }
137151
}
138152
return "text/x-fossil-wiki";
139153
}
140154
141155
/*
@@ -412,27 +426,18 @@
412426
db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nrid);
413427
db_multi_exec("INSERT OR IGNORE INTO unclustered VALUES(%d);", nrid);
414428
manifest_crosslink(nrid, pWiki, MC_NONE);
415429
}
416430
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
-
426431
/*
427432
** Output a selection box from which the user can select the
428433
** wiki mimetype.
429434
*/
430435
void mimetype_option_menu(const char *zMimetype){
431436
unsigned i;
432437
@ <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){
434439
if( fossil_strcmp(zMimetype,azStyles[i])==0 ){
435440
@ <option value="%s(azStyles[i])" selected>%s(azStyles[i+1])</option>
436441
}else{
437442
@ <option value="%s(azStyles[i])">%s(azStyles[i+1])</option>
438443
}
@@ -1314,10 +1319,12 @@
13141319
if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0
13151320
&& (pWiki->zMimetype && *pWiki->zMimetype)){
13161321
zMimeType = pWiki->zMimetype;
13171322
}
13181323
}
1324
+ }else{
1325
+ zMimeType = wiki_filter_mimetypes(zMimeType);
13191326
}
13201327
if( g.argv[2][1]=='r' && rid>0 ){
13211328
if ( !zETime ){
13221329
fossil_fatal("wiki page %s already exists", zPageName);
13231330
}else{
13241331
--- 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

Keyboard Shortcuts

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