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.

drh 2021-09-17 10:46 trunk
Commit d81190bd72dcf74a8fa91b729b1d9c5bd57ee2bb1edc9a986f18a7ff19513732
1 file changed +32
+32
--- src/name.c
+++ src/name.c
@@ -224,10 +224,18 @@
224224
") LIMIT 1;",
225225
zType, zTag, zTag, zType
226226
);
227227
}
228228
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
+
229237
230238
/*
231239
** Convert a symbolic name into a RID. Acceptable forms:
232240
**
233241
** * artifact hash (optionally enclosed in [...])
@@ -485,10 +493,34 @@
485493
" FROM event"
486494
" WHERE event.objid=%s"
487495
" AND event.type GLOB '%q'", zTag /*safe-for-%s*/, zType);
488496
}
489497
}
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);
490522
}
491523
return rid;
492524
}
493525
494526
/*
495527
--- 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

Keyboard Shortcuts

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