修訂 | 95306d1416055e444cb081f352f8e34ae3eaf855 (tree) |
---|---|
時間 | 2017-04-02 15:59:51 |
作者 | umorigu <umorigu@gmai...> |
Commiter | umorigu |
AutoTicketLink: Support hyphen and dot in key
@@ -210,6 +210,9 @@ function get_html_scripting_data() | ||
210 | 210 | }; |
211 | 211 | $text = ''; |
212 | 212 | foreach ($ticket_link_sites as $s) { |
213 | + if (!preg_match('/^([a-zA-Z0-9]+)([\.\-][a-zA-Z0-9]+)*$/', $s['key'])) { | |
214 | + continue; | |
215 | + } | |
213 | 216 | $site_info_json = htmlsc(json_encode($s, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); |
214 | 217 | $text .= <<<EOS |
215 | 218 | <span class="pukiwiki-ticketlink-site" data-site="$site_info_json"></span> |
@@ -18,16 +18,21 @@ if (window.addEventListener) { | ||
18 | 18 | } |
19 | 19 | return ''; |
20 | 20 | } |
21 | + function regexEscape(key) { | |
22 | + return key.replace(/[\-\.]/g, function (m) { | |
23 | + return '\\' + m; | |
24 | + }); | |
25 | + } | |
21 | 26 | function setupSites(siteList) { |
22 | 27 | for (var i = 0, length = siteList.length; i < length; i++) { |
23 | 28 | var site = siteList[i]; |
24 | 29 | var reText = ''; |
25 | 30 | switch (site.type) { |
26 | 31 | case 'jira': |
27 | - reText = '(' + site.key + '):' + '([A-Z][A-Z0-9]+-\\d+)'; | |
32 | + reText = '(' + regexEscape(site.key) + '):' + '([A-Z][A-Z0-9]+-\\d+)'; | |
28 | 33 | break; |
29 | 34 | case 'redmine': |
30 | - reText = '(' + site.key + '):' + '(\\d+)'; | |
35 | + reText = '(' + regexEscape(site.key) + '):' + '(\\d+)'; | |
31 | 36 | break; |
32 | 37 | default: |
33 | 38 | continue; |