diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2017-01-07 10:52:40 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2017-01-07 10:52:40 +0000 |
commit | 79c2e42889913a2f4ec583b4bbc9fbe256d92e7e (patch) | |
tree | 74aeb24611c80616d96bfde474e8ea0a08e3b255 /app | |
parent | 6a1865905f38c37df8e67ef5d3b3564dd3850f81 (diff) | |
download | redmine-79c2e42889913a2f4ec583b4bbc9fbe256d92e7e.tar.gz redmine-79c2e42889913a2f4ec583b4bbc9fbe256d92e7e.zip |
More readable regexp for parse_redmine_links (#24382).
Patch by Dmitry Lisichkin.
git-svn-id: http://svn.redmine.org/redmine/trunk@16152 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/helpers/application_helper.rb | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e6078358d..30bd8eb14 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -797,8 +797,20 @@ module ApplicationHelper # identifier:version:1.0.0 # identifier:source:some/file def parse_redmine_links(text, default_project, obj, attr, only_path, options) - text.gsub!(%r{<a( [^>]+?)?>(.*?)</a>|([\s\(,\-\[\>]|^)(!)?(([a-z0-9\-_]+):)?(attachment|document|version|forum|news|message|project|commit|source|export)?(((#)|((([a-z0-9\-_]+)\|)?(r)))((\d+)((#note)?-(\d+))?)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]][^A-Za-z0-9_/])|,|\s|\]|<|$)}) do |m| - tag_content, leading, esc, project_prefix, project_identifier, prefix, repo_prefix, repo_identifier, sep, identifier, comment_suffix, comment_id = $2, $3, $4, $5, $6, $7, $12, $13, $10 || $14 || $20, $16 || $21, $17, $19 + text.gsub!(LINKS_RE) do |_| + tag_content = $~[:tag_content] + leading = $~[:leading] + esc = $~[:esc] + project_prefix = $~[:project_prefix] + project_identifier = $~[:project_identifier] + prefix = $~[:prefix] + repo_prefix = $~[:repo_prefix] + repo_identifier = $~[:repo_identifier] + sep = $~[:sep1] || $~[:sep2] || $~[:sep3] + identifier = $~[:identifier1] || $~[:identifier2] + comment_suffix = $~[:comment_suffix] + comment_id = $~[:comment_id] + if tag_content $& else @@ -933,6 +945,39 @@ module ApplicationHelper end end + LINKS_RE = + %r{ + <a( [^>]+?)?>(?<tag_content>.*?)</a>| + (?<leading>[\s\(,\-\[\>]|^) + (?<esc>!)? + (?<project_prefix>(?<project_identifier>[a-z0-9\-_]+):)? + (?<prefix>attachment|document|version|forum|news|message|project|commit|source|export)? + ( + ( + (?<sep1>\#)| + ( + (?<repo_prefix>(?<repo_identifier>[a-z0-9\-_]+)\|)? + (?<sep2>r) + ) + ) + ( + (?<identifier1>\d+) + (?<comment_suffix> + (\#note)? + -(?<comment_id>\d+) + )? + )| + (?<sep3>:) + (?<identifier2>[^"\s<>][^\s<>]*?|"[^"]+?") + ) + (?= + (?=[[:punct:]][^A-Za-z0-9_/])| + ,| + \s| + \]| + <| + $) + }x HEADING_RE = /(<h(\d)( [^>]+)?>(.+?)<\/h(\d)>)/i unless const_defined?(:HEADING_RE) def parse_sections(text, project, obj, attr, only_path, options) |