Fossil SCM
Refinement to the URL-to-basename algorithm used to construct a repository filename from a clone URL so that the "www." prefix is not omitted if it is immediately followed by the suffix. [forum/forumpost/74e111a2ee|forum post 74e111a2ee].
Commit
380aa578a8ecbc952672b9dad5b4d8a90a09a93be1948c6602d097183d6eb756
Parent
705d519fff2a49c…
1 file changed
+7
-2
+7
-2
| --- src/url.c | ||
| +++ src/url.c | ||
| @@ -638,11 +638,11 @@ | ||
| 638 | 638 | ** * If the URL has a path, use the tail of the path, with any suffix |
| 639 | 639 | ** elided. |
| 640 | 640 | ** |
| 641 | 641 | ** * If the URL is just a domain name, without a path, then use the |
| 642 | 642 | ** first element of the domain name, except skip over "www." if |
| 643 | -** present. | |
| 643 | +** present and if there is a ".com" or ".org" or similar suffix. | |
| 644 | 644 | ** |
| 645 | 645 | ** The string returned is obtained from fossil_malloc(). NULL might be |
| 646 | 646 | ** returned if there is an error. |
| 647 | 647 | */ |
| 648 | 648 | char *url_to_repo_basename(const char *zUrl){ |
| @@ -652,11 +652,16 @@ | ||
| 652 | 652 | for(i=0; zUrl[i]; i++){ |
| 653 | 653 | if( zUrl[i]=='?' ) break; |
| 654 | 654 | if( (zUrl[i]=='/' || zUrl[i]=='@') && zUrl[i+1]!=0 ) zTail = &zUrl[i+1]; |
| 655 | 655 | } |
| 656 | 656 | if( zTail==0 ) return 0; |
| 657 | - if( sqlite3_strnicmp(zTail, "www.", 4)==0 ) zTail += 4; | |
| 657 | + if( sqlite3_strnicmp(zTail, "www.", 4)==0 && strchr(zTail+4,'.')!=0 ){ | |
| 658 | + /* Remove the "www." prefix if there are more "." characters later. | |
| 659 | + ** But don't remove the "www." prefix if what follows is the suffix. | |
| 660 | + ** forum:/forumpost/74e111a2ee */ | |
| 661 | + zTail += 4; | |
| 662 | + } | |
| 658 | 663 | if( zTail[0]==0 ) return 0; |
| 659 | 664 | for(i=0; zTail[i] && zTail[i]!='.' && zTail[i]!='?'; i++){} |
| 660 | 665 | if( i==0 ) return 0; |
| 661 | 666 | return mprintf("%.*s", i, zTail); |
| 662 | 667 | } |
| 663 | 668 |
| --- src/url.c | |
| +++ src/url.c | |
| @@ -638,11 +638,11 @@ | |
| 638 | ** * If the URL has a path, use the tail of the path, with any suffix |
| 639 | ** elided. |
| 640 | ** |
| 641 | ** * If the URL is just a domain name, without a path, then use the |
| 642 | ** first element of the domain name, except skip over "www." if |
| 643 | ** present. |
| 644 | ** |
| 645 | ** The string returned is obtained from fossil_malloc(). NULL might be |
| 646 | ** returned if there is an error. |
| 647 | */ |
| 648 | char *url_to_repo_basename(const char *zUrl){ |
| @@ -652,11 +652,16 @@ | |
| 652 | for(i=0; zUrl[i]; i++){ |
| 653 | if( zUrl[i]=='?' ) break; |
| 654 | if( (zUrl[i]=='/' || zUrl[i]=='@') && zUrl[i+1]!=0 ) zTail = &zUrl[i+1]; |
| 655 | } |
| 656 | if( zTail==0 ) return 0; |
| 657 | if( sqlite3_strnicmp(zTail, "www.", 4)==0 ) zTail += 4; |
| 658 | if( zTail[0]==0 ) return 0; |
| 659 | for(i=0; zTail[i] && zTail[i]!='.' && zTail[i]!='?'; i++){} |
| 660 | if( i==0 ) return 0; |
| 661 | return mprintf("%.*s", i, zTail); |
| 662 | } |
| 663 |
| --- src/url.c | |
| +++ src/url.c | |
| @@ -638,11 +638,11 @@ | |
| 638 | ** * If the URL has a path, use the tail of the path, with any suffix |
| 639 | ** elided. |
| 640 | ** |
| 641 | ** * If the URL is just a domain name, without a path, then use the |
| 642 | ** first element of the domain name, except skip over "www." if |
| 643 | ** present and if there is a ".com" or ".org" or similar suffix. |
| 644 | ** |
| 645 | ** The string returned is obtained from fossil_malloc(). NULL might be |
| 646 | ** returned if there is an error. |
| 647 | */ |
| 648 | char *url_to_repo_basename(const char *zUrl){ |
| @@ -652,11 +652,16 @@ | |
| 652 | for(i=0; zUrl[i]; i++){ |
| 653 | if( zUrl[i]=='?' ) break; |
| 654 | if( (zUrl[i]=='/' || zUrl[i]=='@') && zUrl[i+1]!=0 ) zTail = &zUrl[i+1]; |
| 655 | } |
| 656 | if( zTail==0 ) return 0; |
| 657 | if( sqlite3_strnicmp(zTail, "www.", 4)==0 && strchr(zTail+4,'.')!=0 ){ |
| 658 | /* Remove the "www." prefix if there are more "." characters later. |
| 659 | ** But don't remove the "www." prefix if what follows is the suffix. |
| 660 | ** forum:/forumpost/74e111a2ee */ |
| 661 | zTail += 4; |
| 662 | } |
| 663 | if( zTail[0]==0 ) return 0; |
| 664 | for(i=0; zTail[i] && zTail[i]!='.' && zTail[i]!='?'; i++){} |
| 665 | if( i==0 ) return 0; |
| 666 | return mprintf("%.*s", i, zTail); |
| 667 | } |
| 668 |