Fossil SCM
Tolerate one or two punctuation characters at the end of a symbolic name, if the name does not otherwise match, to accomodate names taken from the ends of URLs where some extra punctuation from the following text was included with the URL.
Commit
d81190bd72dcf74a8fa91b729b1d9c5bd57ee2bb1edc9a986f18a7ff19513732
Parent
36d84427f6e2e79…
1 file changed
+32
+32
| --- src/name.c | ||
| +++ src/name.c | ||
| @@ -224,10 +224,18 @@ | ||
| 224 | 224 | ") LIMIT 1;", |
| 225 | 225 | zType, zTag, zTag, zType |
| 226 | 226 | ); |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | +/* | |
| 230 | +** Return true if character "c" is a character that might have been | |
| 231 | +** accidentally appended to the end of a URL. | |
| 232 | +*/ | |
| 233 | +static int is_trailing_punct(char c){ | |
| 234 | + return c=='.' || c=='_' || c==')' || c=='>' || c=='!' || c=='?' || c==','; | |
| 235 | +} | |
| 236 | + | |
| 229 | 237 | |
| 230 | 238 | /* |
| 231 | 239 | ** Convert a symbolic name into a RID. Acceptable forms: |
| 232 | 240 | ** |
| 233 | 241 | ** * artifact hash (optionally enclosed in [...]) |
| @@ -485,10 +493,34 @@ | ||
| 485 | 493 | " FROM event" |
| 486 | 494 | " WHERE event.objid=%s" |
| 487 | 495 | " AND event.type GLOB '%q'", zTag /*safe-for-%s*/, zType); |
| 488 | 496 | } |
| 489 | 497 | } |
| 498 | + return rid; | |
| 499 | + } | |
| 500 | + | |
| 501 | + /* If nothing matches and the name ends with punctuation, | |
| 502 | + ** then the name might have originated from a URL in plain text | |
| 503 | + ** that was incorrectly extracted from the text. Try to remove | |
| 504 | + ** the extra punctuation and rerun the match. | |
| 505 | + */ | |
| 506 | + if( nTag>4 | |
| 507 | + && is_trailing_punct(zTag[nTag-1]) | |
| 508 | + && !is_trailing_punct(zTag[nTag-2]) | |
| 509 | + ){ | |
| 510 | + char *zNew = fossil_strndup(zTag, nTag-1); | |
| 511 | + rid = symbolic_name_to_rid(zNew,zType); | |
| 512 | + fossil_free(zNew); | |
| 513 | + }else | |
| 514 | + if( nTag>5 | |
| 515 | + && is_trailing_punct(zTag[nTag-1]) | |
| 516 | + && is_trailing_punct(zTag[nTag-2]) | |
| 517 | + && !is_trailing_punct(zTag[nTag-3]) | |
| 518 | + ){ | |
| 519 | + char *zNew = fossil_strndup(zTag, nTag-2); | |
| 520 | + rid = symbolic_name_to_rid(zNew,zType); | |
| 521 | + fossil_free(zNew); | |
| 490 | 522 | } |
| 491 | 523 | return rid; |
| 492 | 524 | } |
| 493 | 525 | |
| 494 | 526 | /* |
| 495 | 527 |
| --- src/name.c | |
| +++ src/name.c | |
| @@ -224,10 +224,18 @@ | |
| 224 | ") LIMIT 1;", |
| 225 | zType, zTag, zTag, zType |
| 226 | ); |
| 227 | } |
| 228 | |
| 229 | |
| 230 | /* |
| 231 | ** Convert a symbolic name into a RID. Acceptable forms: |
| 232 | ** |
| 233 | ** * artifact hash (optionally enclosed in [...]) |
| @@ -485,10 +493,34 @@ | |
| 485 | " FROM event" |
| 486 | " WHERE event.objid=%s" |
| 487 | " AND event.type GLOB '%q'", zTag /*safe-for-%s*/, zType); |
| 488 | } |
| 489 | } |
| 490 | } |
| 491 | return rid; |
| 492 | } |
| 493 | |
| 494 | /* |
| 495 |
| --- src/name.c | |
| +++ src/name.c | |
| @@ -224,10 +224,18 @@ | |
| 224 | ") LIMIT 1;", |
| 225 | zType, zTag, zTag, zType |
| 226 | ); |
| 227 | } |
| 228 | |
| 229 | /* |
| 230 | ** Return true if character "c" is a character that might have been |
| 231 | ** accidentally appended to the end of a URL. |
| 232 | */ |
| 233 | static int is_trailing_punct(char c){ |
| 234 | return c=='.' || c=='_' || c==')' || c=='>' || c=='!' || c=='?' || c==','; |
| 235 | } |
| 236 | |
| 237 | |
| 238 | /* |
| 239 | ** Convert a symbolic name into a RID. Acceptable forms: |
| 240 | ** |
| 241 | ** * artifact hash (optionally enclosed in [...]) |
| @@ -485,10 +493,34 @@ | |
| 493 | " FROM event" |
| 494 | " WHERE event.objid=%s" |
| 495 | " AND event.type GLOB '%q'", zTag /*safe-for-%s*/, zType); |
| 496 | } |
| 497 | } |
| 498 | return rid; |
| 499 | } |
| 500 | |
| 501 | /* If nothing matches and the name ends with punctuation, |
| 502 | ** then the name might have originated from a URL in plain text |
| 503 | ** that was incorrectly extracted from the text. Try to remove |
| 504 | ** the extra punctuation and rerun the match. |
| 505 | */ |
| 506 | if( nTag>4 |
| 507 | && is_trailing_punct(zTag[nTag-1]) |
| 508 | && !is_trailing_punct(zTag[nTag-2]) |
| 509 | ){ |
| 510 | char *zNew = fossil_strndup(zTag, nTag-1); |
| 511 | rid = symbolic_name_to_rid(zNew,zType); |
| 512 | fossil_free(zNew); |
| 513 | }else |
| 514 | if( nTag>5 |
| 515 | && is_trailing_punct(zTag[nTag-1]) |
| 516 | && is_trailing_punct(zTag[nTag-2]) |
| 517 | && !is_trailing_punct(zTag[nTag-3]) |
| 518 | ){ |
| 519 | char *zNew = fossil_strndup(zTag, nTag-2); |
| 520 | rid = symbolic_name_to_rid(zNew,zType); |
| 521 | fossil_free(zNew); |
| 522 | } |
| 523 | return rid; |
| 524 | } |
| 525 | |
| 526 | /* |
| 527 |