@@ -37,38 +37,31 @@ sub unescape-percent($s) {
37
37
}
38
38
39
39
sub rewrite-url ($ s ) is export {
40
- state % cache ;
40
+ state % cache =
41
+ ' /routine//' => ' /routine/' ~ replace-badchars-with-goodnames(' /' ),
42
+ ' /routine///' => ' /routine/' ~ replace-badchars-with-goodnames(' //' );
41
43
return % cache {$ s } if % cache {$ s }: exists ;
44
+
42
45
my Str $ r ;
43
46
given $ s {
44
- when / ^ [ 'http' | 'https' | 'irc' ] '://' / {
45
- # external link, we bail
46
- return $ s ;
47
- }
48
-
49
- when / ^ '#' / {
50
- # on-page link, we bail
51
- return $ s ;
47
+ # Avoiding Junctions as matchers due to:
48
+ # https://github.com/rakudo/rakudo/issues/1385#issuecomment-377895230
49
+ when { . starts-with : ' https://' or . starts-with : ' #'
50
+ or . starts-with : ' http://' or . starts-with : ' irc://'
51
+ } {
52
+ return % cache {$ s } = $ s ; # external link or on-page-link, we bail
52
53
}
53
54
# Type
54
- when / ^ < [ A..Z ] > / {
55
+ when ' A ' . ord ≤ *. ord ≤ ' Z ' . ord {
55
56
$ r = " /type/{ replace-badchars-with-goodnames(unescape-percent($ s ))} " ;
56
- succeed;
57
57
}
58
58
# Routine
59
59
when / ^ <[ a..z ] > | ^ <- alpha >* $ / {
60
60
$ r = " /routine/{ replace-badchars-with-goodnames(unescape-percent($ s ))} " ;
61
- succeed;
62
61
}
63
-
64
- # Special case the really nasty ones
65
- when / ^ '/routine//' $ / { return ' /routine/' ~ replace-badchars-with-goodnames(' /' ); succeed; }
66
- when / ^ '/routine///' $ / { return ' /routine/' ~ replace-badchars-with-goodnames(' //' ); succeed; }
67
-
68
62
when / ^
69
63
([ '/routine/' | '/syntax/' | '/language/' | '/programs/' | '/type/' ]) (<- [ #/ ] >+ ) [ ('#' ) (<- [ # ] >* ) ]* $ / {
70
64
$ r = $0 ~ replace-badchars-with-goodnames(unescape-percent($1 )) ~ $2 ~ uri_escape($3 );
71
- succeed;
72
65
}
73
66
74
67
default {
0 commit comments