diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2018-06-17 05:45:17 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2018-06-17 05:45:17 +0000 |
commit | 270b6c4d7eef3fcc38657ad411553da47a2e958b (patch) | |
tree | 1a0c38b3343c272fda2353c0b34fff637005e2f7 /lib | |
parent | 74d775166a89ae97c0bed869bbf70ae338d61b8c (diff) | |
download | redmine-270b6c4d7eef3fcc38657ad411553da47a2e958b.tar.gz redmine-270b6c4d7eef3fcc38657ad411553da47a2e958b.zip |
User link syntax (user:login) doesn't work for logins consisting of an email adress (#26443).
Patch by Marius BALTEANU.
git-svn-id: http://svn.redmine.org/redmine/trunk@17392 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib')
-rw-r--r-- | lib/redmine/wiki_formatting.rb | 23 | ||||
-rw-r--r-- | lib/redmine/wiki_formatting/markdown/formatter.rb | 16 | ||||
-rw-r--r-- | lib/redmine/wiki_formatting/textile/formatter.rb | 3 |
3 files changed, 28 insertions, 14 deletions
diff --git a/lib/redmine/wiki_formatting.rb b/lib/redmine/wiki_formatting.rb index bb9089218..9a2de5cff 100644 --- a/lib/redmine/wiki_formatting.rb +++ b/lib/redmine/wiki_formatting.rb @@ -153,7 +153,7 @@ module Redmine # Destructively replaces email addresses into clickable links def auto_mailto!(text) - text.gsub!(/((?<!@)\b[\w\.!#\$%\-+.\/]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/) do + text.gsub!(/([\w\.!#\$%\-+.\/]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/) do mail = $1 if text.match(/<a\b[^>]*>(.*)(#{Regexp.escape(mail)})(.*)<\/a>/) mail @@ -162,6 +162,26 @@ module Redmine end end end + + def restore_redmine_links(html) + # restore wiki links eg. [[Foo]] + html.gsub!(%r{\[<a href="(.*?)">(.*?)</a>\]}) do + "[[#{$2}]]" + end + # restore Redmine links with double-quotes, eg. version:"1.0" + html.gsub!(/(\w):"(.+?)"/) do + "#{$1}:\"#{$2}\"" + end + # restore user links with @ in login name eg. [@jsmith@somenet.foo] + html.gsub!(%r{[@\A]<a(\sclass="email")? href="mailto:(.*?)">(.*?)</a>}) do + "@#{$2}" + end + # restore user links with @ in login name eg. [user:jsmith@somenet.foo] + html.gsub!(%r{\buser:<a(\sclass="email")? href="mailto:(.*?)">(.*?)<\/a>}) do + "user:#{$2}" + end + html + end end # Default formatter module @@ -180,6 +200,7 @@ module Redmine t = CGI::escapeHTML(@text) auto_link!(t) auto_mailto!(t) + restore_redmine_links(t) simple_format(t, {}, :sanitize => false) end end diff --git a/lib/redmine/wiki_formatting/markdown/formatter.rb b/lib/redmine/wiki_formatting/markdown/formatter.rb index b5ee2c941..4bfd00c79 100644 --- a/lib/redmine/wiki_formatting/markdown/formatter.rb +++ b/lib/redmine/wiki_formatting/markdown/formatter.rb @@ -52,24 +52,16 @@ module Redmine end class Formatter + include Redmine::WikiFormatting::LinksHelper + alias :inline_restore_redmine_links :restore_redmine_links + def initialize(text) @text = text end def to_html(*args) html = formatter.render(@text) - # restore wiki links eg. [[Foo]] - html.gsub!(%r{\[<a href="(.*?)">(.*?)</a>\]}) do - "[[#{$2}]]" - end - # restore Redmine links with double-quotes, eg. version:"1.0" - html.gsub!(/(\w):"(.+?)"/) do - "#{$1}:\"#{$2}\"" - end - # restore user links with @ in login name eg. [@jsmith@somenet.foo] - html.gsub!(%r{[@\A]<a href="mailto:(.*?)">(.*?)</a>}) do - "@#{$2}" - end + html = inline_restore_redmine_links(html) html end diff --git a/lib/redmine/wiki_formatting/textile/formatter.rb b/lib/redmine/wiki_formatting/textile/formatter.rb index 6e7f28e62..b0b65bbbc 100644 --- a/lib/redmine/wiki_formatting/textile/formatter.rb +++ b/lib/redmine/wiki_formatting/textile/formatter.rb @@ -27,9 +27,10 @@ module Redmine alias :inline_auto_link :auto_link! alias :inline_auto_mailto :auto_mailto! + alias :inline_restore_redmine_links :restore_redmine_links # auto_link rule after textile rules so that it doesn't break !image_url! tags - RULES = [:textile, :block_markdown_rule, :inline_auto_link, :inline_auto_mailto] + RULES = [:textile, :block_markdown_rule, :inline_auto_link, :inline_auto_mailto, :inline_restore_redmine_links] def initialize(*args) super |