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.
Commit
8b4b4247dcf0dee75da7cfd6d785c9c8937d4cdc
Parent
ef108998c4fb826…
1 file changed
+7
-5
+7
-5
| --- src/doc.c | ||
| +++ src/doc.c | ||
| @@ -390,36 +390,38 @@ | ||
| 390 | 390 | char *zCheckin = "tip"; /* The checkin holding the document */ |
| 391 | 391 | int vid = 0; /* Artifact of checkin */ |
| 392 | 392 | int rid = 0; /* Artifact of file */ |
| 393 | 393 | int i; /* Loop counter */ |
| 394 | 394 | 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 */ | |
| 396 | 396 | static const char *azSuffix[] = { |
| 397 | 397 | "index.html", "index.wiki", "index.md" |
| 398 | 398 | }; |
| 399 | 399 | |
| 400 | 400 | login_check_credentials(); |
| 401 | 401 | if( !g.perm.Read ){ login_needed(); return; } |
| 402 | - for(nMiss=0; rid==0 && nMiss<=ArraySize(azSuffix); nMiss++){ | |
| 402 | + while( rid==0 && (++nMiss)<=ArraySize(azSuffix) ){ | |
| 403 | 403 | zName = PD("name", "tip/index.wiki"); |
| 404 | 404 | for(i=0; zName[i] && zName[i]!='/'; i++){} |
| 405 | 405 | zCheckin = mprintf("%.*s", i, zName); |
| 406 | 406 | if( fossil_strcmp(zCheckin,"ckout")==0 && db_open_local(0)==0 ){ |
| 407 | 407 | zCheckin = "tip"; |
| 408 | 408 | } |
| 409 | 409 | if( nMiss==ArraySize(azSuffix) ){ |
| 410 | 410 | zName = "404.md"; |
| 411 | 411 | }else if( zName[i]==0 ){ |
| 412 | + assert( nMiss>=0 && nMiss<ArraySize(azSuffix) ); | |
| 412 | 413 | zName = azSuffix[nMiss]; |
| 413 | 414 | }else{ |
| 414 | 415 | zName += i; |
| 415 | 416 | } |
| 416 | 417 | while( zName[0]=='/' ){ zName++; } |
| 417 | 418 | g.zPath = mprintf("%s/%s/%s", g.zPath, zCheckin, zName); |
| 418 | 419 | if( nMiss==0 ) zOrigName = zName; |
| 419 | 420 | if( !file_is_simple_pathname(zName, 1) ){ |
| 420 | 421 | if( sqlite3_strglob("*/", zName)==0 ){ |
| 422 | + assert( nMiss>=0 && nMiss<ArraySize(azSuffix) ); | |
| 421 | 423 | zName = mprintf("%s%s", zName, azSuffix[nMiss]); |
| 422 | 424 | if( !file_is_simple_pathname(zName, 1) ){ |
| 423 | 425 | goto doc_not_found; |
| 424 | 426 | } |
| 425 | 427 | }else{ |
| @@ -458,11 +460,10 @@ | ||
| 458 | 460 | vid |
| 459 | 461 | ); |
| 460 | 462 | } |
| 461 | 463 | rid = db_int(0, "SELECT rid FROM vcache" |
| 462 | 464 | " WHERE vid=%d AND fname=%Q", vid, zName); |
| 463 | - nMiss++; | |
| 464 | 465 | if( rid==0 || content_get(rid, &filebody)==0 ){ |
| 465 | 466 | goto doc_not_found; |
| 466 | 467 | } |
| 467 | 468 | db_end_transaction(0); |
| 468 | 469 | } |
| @@ -498,11 +499,12 @@ | ||
| 498 | 499 | Blob tail = BLOB_INITIALIZER; |
| 499 | 500 | markdown_to_html(&filebody, &title, &tail); |
| 500 | 501 | if( blob_size(&title)>0 ){ |
| 501 | 502 | style_header("%s", blob_str(&title)); |
| 502 | 503 | }else{ |
| 503 | - style_header("%s", nMiss?"Not Found":"Documentation"); | |
| 504 | + style_header("%s", nMiss>=ArraySize(azSuffix)? | |
| 505 | + "Not Found" : "Documentation"); | |
| 504 | 506 | } |
| 505 | 507 | blob_append(cgi_output_blob(), blob_buffer(&tail), blob_size(&tail)); |
| 506 | 508 | style_footer(); |
| 507 | 509 | }else if( fossil_strcmp(zMime, "text/plain")==0 ){ |
| 508 | 510 | style_header("Documentation"); |
| @@ -519,11 +521,11 @@ | ||
| 519 | 521 | #endif |
| 520 | 522 | }else{ |
| 521 | 523 | cgi_set_content_type(zMime); |
| 522 | 524 | cgi_set_content(&filebody); |
| 523 | 525 | } |
| 524 | - if( nMiss ) cgi_set_status(404, "Not Found"); | |
| 526 | + if( nMiss>=ArraySize(azSuffix) ) cgi_set_status(404, "Not Found"); | |
| 525 | 527 | return; |
| 526 | 528 | |
| 527 | 529 | /* Jump here when unable to locate the document */ |
| 528 | 530 | doc_not_found: |
| 529 | 531 | db_end_transaction(0); |
| 530 | 532 |
| --- 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 |