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].

drh 2021-05-13 19:38 trunk
Commit 380aa578a8ecbc952672b9dad5b4d8a90a09a93be1948c6602d097183d6eb756
1 file changed +7 -2
+7 -2
--- src/url.c
+++ src/url.c
@@ -638,11 +638,11 @@
638638
** * If the URL has a path, use the tail of the path, with any suffix
639639
** elided.
640640
**
641641
** * If the URL is just a domain name, without a path, then use the
642642
** 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.
644644
**
645645
** The string returned is obtained from fossil_malloc(). NULL might be
646646
** returned if there is an error.
647647
*/
648648
char *url_to_repo_basename(const char *zUrl){
@@ -652,11 +652,16 @@
652652
for(i=0; zUrl[i]; i++){
653653
if( zUrl[i]=='?' ) break;
654654
if( (zUrl[i]=='/' || zUrl[i]=='@') && zUrl[i+1]!=0 ) zTail = &zUrl[i+1];
655655
}
656656
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
+ }
658663
if( zTail[0]==0 ) return 0;
659664
for(i=0; zTail[i] && zTail[i]!='.' && zTail[i]!='?'; i++){}
660665
if( i==0 ) return 0;
661666
return mprintf("%.*s", i, zTail);
662667
}
663668
--- 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

Keyboard Shortcuts

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