Fossil SCM

Fix the /doc page so that it returns status 200 (not 404) after appending "index.html" to the end of a page name.

drh 2015-01-29 01:48 trunk
Commit 8b4b4247dcf0dee75da7cfd6d785c9c8937d4cdc
1 file changed +7 -5
+7 -5
--- src/doc.c
+++ src/doc.c
@@ -390,36 +390,38 @@
390390
char *zCheckin = "tip"; /* The checkin holding the document */
391391
int vid = 0; /* Artifact of checkin */
392392
int rid = 0; /* Artifact of file */
393393
int i; /* Loop counter */
394394
Blob filebody; /* Content of the documentation file */
395
- int nMiss = 0; /* Failed attempts to find the document */
395
+ int nMiss = (-1); /* Failed attempts to find the document */
396396
static const char *azSuffix[] = {
397397
"index.html", "index.wiki", "index.md"
398398
};
399399
400400
login_check_credentials();
401401
if( !g.perm.Read ){ login_needed(); return; }
402
- for(nMiss=0; rid==0 && nMiss<=ArraySize(azSuffix); nMiss++){
402
+ while( rid==0 && (++nMiss)<=ArraySize(azSuffix) ){
403403
zName = PD("name", "tip/index.wiki");
404404
for(i=0; zName[i] && zName[i]!='/'; i++){}
405405
zCheckin = mprintf("%.*s", i, zName);
406406
if( fossil_strcmp(zCheckin,"ckout")==0 && db_open_local(0)==0 ){
407407
zCheckin = "tip";
408408
}
409409
if( nMiss==ArraySize(azSuffix) ){
410410
zName = "404.md";
411411
}else if( zName[i]==0 ){
412
+ assert( nMiss>=0 && nMiss<ArraySize(azSuffix) );
412413
zName = azSuffix[nMiss];
413414
}else{
414415
zName += i;
415416
}
416417
while( zName[0]=='/' ){ zName++; }
417418
g.zPath = mprintf("%s/%s/%s", g.zPath, zCheckin, zName);
418419
if( nMiss==0 ) zOrigName = zName;
419420
if( !file_is_simple_pathname(zName, 1) ){
420421
if( sqlite3_strglob("*/", zName)==0 ){
422
+ assert( nMiss>=0 && nMiss<ArraySize(azSuffix) );
421423
zName = mprintf("%s%s", zName, azSuffix[nMiss]);
422424
if( !file_is_simple_pathname(zName, 1) ){
423425
goto doc_not_found;
424426
}
425427
}else{
@@ -458,11 +460,10 @@
458460
vid
459461
);
460462
}
461463
rid = db_int(0, "SELECT rid FROM vcache"
462464
" WHERE vid=%d AND fname=%Q", vid, zName);
463
- nMiss++;
464465
if( rid==0 || content_get(rid, &filebody)==0 ){
465466
goto doc_not_found;
466467
}
467468
db_end_transaction(0);
468469
}
@@ -498,11 +499,12 @@
498499
Blob tail = BLOB_INITIALIZER;
499500
markdown_to_html(&filebody, &title, &tail);
500501
if( blob_size(&title)>0 ){
501502
style_header("%s", blob_str(&title));
502503
}else{
503
- style_header("%s", nMiss?"Not Found":"Documentation");
504
+ style_header("%s", nMiss>=ArraySize(azSuffix)?
505
+ "Not Found" : "Documentation");
504506
}
505507
blob_append(cgi_output_blob(), blob_buffer(&tail), blob_size(&tail));
506508
style_footer();
507509
}else if( fossil_strcmp(zMime, "text/plain")==0 ){
508510
style_header("Documentation");
@@ -519,11 +521,11 @@
519521
#endif
520522
}else{
521523
cgi_set_content_type(zMime);
522524
cgi_set_content(&filebody);
523525
}
524
- if( nMiss ) cgi_set_status(404, "Not Found");
526
+ if( nMiss>=ArraySize(azSuffix) ) cgi_set_status(404, "Not Found");
525527
return;
526528
527529
/* Jump here when unable to locate the document */
528530
doc_not_found:
529531
db_end_transaction(0);
530532
--- src/doc.c
+++ src/doc.c
@@ -390,36 +390,38 @@
390 char *zCheckin = "tip"; /* The checkin holding the document */
391 int vid = 0; /* Artifact of checkin */
392 int rid = 0; /* Artifact of file */
393 int i; /* Loop counter */
394 Blob filebody; /* Content of the documentation file */
395 int nMiss = 0; /* Failed attempts to find the document */
396 static const char *azSuffix[] = {
397 "index.html", "index.wiki", "index.md"
398 };
399
400 login_check_credentials();
401 if( !g.perm.Read ){ login_needed(); return; }
402 for(nMiss=0; rid==0 && nMiss<=ArraySize(azSuffix); nMiss++){
403 zName = PD("name", "tip/index.wiki");
404 for(i=0; zName[i] && zName[i]!='/'; i++){}
405 zCheckin = mprintf("%.*s", i, zName);
406 if( fossil_strcmp(zCheckin,"ckout")==0 && db_open_local(0)==0 ){
407 zCheckin = "tip";
408 }
409 if( nMiss==ArraySize(azSuffix) ){
410 zName = "404.md";
411 }else if( zName[i]==0 ){
 
412 zName = azSuffix[nMiss];
413 }else{
414 zName += i;
415 }
416 while( zName[0]=='/' ){ zName++; }
417 g.zPath = mprintf("%s/%s/%s", g.zPath, zCheckin, zName);
418 if( nMiss==0 ) zOrigName = zName;
419 if( !file_is_simple_pathname(zName, 1) ){
420 if( sqlite3_strglob("*/", zName)==0 ){
 
421 zName = mprintf("%s%s", zName, azSuffix[nMiss]);
422 if( !file_is_simple_pathname(zName, 1) ){
423 goto doc_not_found;
424 }
425 }else{
@@ -458,11 +460,10 @@
458 vid
459 );
460 }
461 rid = db_int(0, "SELECT rid FROM vcache"
462 " WHERE vid=%d AND fname=%Q", vid, zName);
463 nMiss++;
464 if( rid==0 || content_get(rid, &filebody)==0 ){
465 goto doc_not_found;
466 }
467 db_end_transaction(0);
468 }
@@ -498,11 +499,12 @@
498 Blob tail = BLOB_INITIALIZER;
499 markdown_to_html(&filebody, &title, &tail);
500 if( blob_size(&title)>0 ){
501 style_header("%s", blob_str(&title));
502 }else{
503 style_header("%s", nMiss?"Not Found":"Documentation");
 
504 }
505 blob_append(cgi_output_blob(), blob_buffer(&tail), blob_size(&tail));
506 style_footer();
507 }else if( fossil_strcmp(zMime, "text/plain")==0 ){
508 style_header("Documentation");
@@ -519,11 +521,11 @@
519 #endif
520 }else{
521 cgi_set_content_type(zMime);
522 cgi_set_content(&filebody);
523 }
524 if( nMiss ) cgi_set_status(404, "Not Found");
525 return;
526
527 /* Jump here when unable to locate the document */
528 doc_not_found:
529 db_end_transaction(0);
530
--- src/doc.c
+++ src/doc.c
@@ -390,36 +390,38 @@
390 char *zCheckin = "tip"; /* The checkin holding the document */
391 int vid = 0; /* Artifact of checkin */
392 int rid = 0; /* Artifact of file */
393 int i; /* Loop counter */
394 Blob filebody; /* Content of the documentation file */
395 int nMiss = (-1); /* Failed attempts to find the document */
396 static const char *azSuffix[] = {
397 "index.html", "index.wiki", "index.md"
398 };
399
400 login_check_credentials();
401 if( !g.perm.Read ){ login_needed(); return; }
402 while( rid==0 && (++nMiss)<=ArraySize(azSuffix) ){
403 zName = PD("name", "tip/index.wiki");
404 for(i=0; zName[i] && zName[i]!='/'; i++){}
405 zCheckin = mprintf("%.*s", i, zName);
406 if( fossil_strcmp(zCheckin,"ckout")==0 && db_open_local(0)==0 ){
407 zCheckin = "tip";
408 }
409 if( nMiss==ArraySize(azSuffix) ){
410 zName = "404.md";
411 }else if( zName[i]==0 ){
412 assert( nMiss>=0 && nMiss<ArraySize(azSuffix) );
413 zName = azSuffix[nMiss];
414 }else{
415 zName += i;
416 }
417 while( zName[0]=='/' ){ zName++; }
418 g.zPath = mprintf("%s/%s/%s", g.zPath, zCheckin, zName);
419 if( nMiss==0 ) zOrigName = zName;
420 if( !file_is_simple_pathname(zName, 1) ){
421 if( sqlite3_strglob("*/", zName)==0 ){
422 assert( nMiss>=0 && nMiss<ArraySize(azSuffix) );
423 zName = mprintf("%s%s", zName, azSuffix[nMiss]);
424 if( !file_is_simple_pathname(zName, 1) ){
425 goto doc_not_found;
426 }
427 }else{
@@ -458,11 +460,10 @@
460 vid
461 );
462 }
463 rid = db_int(0, "SELECT rid FROM vcache"
464 " WHERE vid=%d AND fname=%Q", vid, zName);
 
465 if( rid==0 || content_get(rid, &filebody)==0 ){
466 goto doc_not_found;
467 }
468 db_end_transaction(0);
469 }
@@ -498,11 +499,12 @@
499 Blob tail = BLOB_INITIALIZER;
500 markdown_to_html(&filebody, &title, &tail);
501 if( blob_size(&title)>0 ){
502 style_header("%s", blob_str(&title));
503 }else{
504 style_header("%s", nMiss>=ArraySize(azSuffix)?
505 "Not Found" : "Documentation");
506 }
507 blob_append(cgi_output_blob(), blob_buffer(&tail), blob_size(&tail));
508 style_footer();
509 }else if( fossil_strcmp(zMime, "text/plain")==0 ){
510 style_header("Documentation");
@@ -519,11 +521,11 @@
521 #endif
522 }else{
523 cgi_set_content_type(zMime);
524 cgi_set_content(&filebody);
525 }
526 if( nMiss>=ArraySize(azSuffix) ) cgi_set_status(404, "Not Found");
527 return;
528
529 /* Jump here when unable to locate the document */
530 doc_not_found:
531 db_end_transaction(0);
532

Keyboard Shortcuts

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