Commit 0eeafe7
committed
fix: anchor first template literal at position 0, not rightmost occurrence
The R->L scan used rfind to locate the literal preceding a variable.
When that literal is the first atom of the template and its text
appears inside the variable's value, rfind lands on the occurrence
inside the value rather than at position 0, leaving unconsumed
characters and returning None.
UriTemplate.parse("prefix-{id}").match("prefix-prefix-123")
# returned None; regex returns {'id': 'prefix-123'}
For templates without a greedy variable, the atom sequence IS the
whole template, so atoms[0] is positionally fixed at URI position 0.
_scan_suffix now takes an anchored flag: when set, the first-atom
literal anchors at 0 rather than searching via rfind.
Also: adjacent captures now skip the stop-char scan entirely since the
result was discarded (start = pos). This drops the worst-case from
O(n*v) to O(n + v) for the pathological all-adjacent-vars case
(497ms -> 2ms for 256 vars against 64KB), and the module docstring
now states the complexity accurately.1 parent ba784d3 commit 0eeafe7
File tree
2 files changed
+60
-10
lines changed2 files changed
+60
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| |||
521 | 523 | | |
522 | 524 | | |
523 | 525 | | |
524 | | - | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
525 | 531 | | |
526 | 532 | | |
527 | 533 | | |
| |||
903 | 909 | | |
904 | 910 | | |
905 | 911 | | |
906 | | - | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
907 | 915 | | |
908 | 916 | | |
909 | 917 | | |
910 | 918 | | |
911 | 919 | | |
912 | 920 | | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
913 | 925 | | |
914 | 926 | | |
915 | 927 | | |
| |||
947 | 959 | | |
948 | 960 | | |
949 | 961 | | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
950 | 970 | | |
951 | 971 | | |
952 | 972 | | |
| |||
955 | 975 | | |
956 | 976 | | |
957 | 977 | | |
958 | | - | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
959 | 987 | | |
960 | 988 | | |
961 | 989 | | |
962 | 990 | | |
963 | 991 | | |
964 | 992 | | |
965 | | - | |
966 | | - | |
967 | | - | |
968 | | - | |
969 | 993 | | |
970 | 994 | | |
971 | 995 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
539 | 539 | | |
540 | 540 | | |
541 | 541 | | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
542 | 568 | | |
543 | 569 | | |
544 | 570 | | |
| |||
0 commit comments