diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-09-13 23:17:03 -0700 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-09-13 23:17:03 -0700 |
commit | 3ecc4df4b35080d78f83c5155418339aad40dca8 (patch) | |
tree | d42343e4eded7ca22e545e291dc8b637dbcda061 /lib | |
parent | 85def2d62500afdab39956f0bd987340889894c4 (diff) | |
parent | d993f666423744d213d7cce063b48e71fa751d43 (diff) | |
download | gitlab-ce-3ecc4df4b35080d78f83c5155418339aad40dca8.tar.gz |
Merge pull request #1456 from tsigo/issue_1308
Fix HTML entities being parsed in GFM
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/markdown.rb | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/gitlab/markdown.rb b/lib/gitlab/markdown.rb index 4fc0c392cac..0a467a8d9c9 100644 --- a/lib/gitlab/markdown.rb +++ b/lib/gitlab/markdown.rb @@ -26,13 +26,13 @@ module Gitlab # => "<img alt=\":trollface:\" class=\"emoji\" src=\"/images/trollface.png" title=\":trollface:\" /> module Markdown REFERENCE_PATTERN = %r{ - ([^\w&;])? # Prefix (1) + (\W)? # Prefix (1) ( # Reference (2) @([\w\._]+) # User name (3) |[#!$](\d+) # Issue/MR/Snippet ID (4) |([\h]{6,40}) # Commit ID (5) ) - ([^\w&;])? # Suffix (6) + (\W)? # Suffix (6) }x.freeze EMOJI_PATTERN = %r{(:(\S+):)}.freeze @@ -84,6 +84,13 @@ module Gitlab # # Returns parsed text def parse(text) + parse_references(text) if @project + parse_emoji(text) + + text + end + + def parse_references(text) # parse reference links text.gsub!(REFERENCE_PATTERN) do |match| prefix = $1 || '' @@ -91,13 +98,18 @@ module Gitlab identifier = $3 || $4 || $5 suffix = $6 || '' - if ref_link = reference_link(reference, identifier) + # Avoid HTML entities + if prefix.ends_with?('&') || suffix.starts_with?(';') + match + elsif ref_link = reference_link(reference, identifier) prefix + ref_link + suffix else match end - end if @project + end + end + def parse_emoji(text) # parse emoji text.gsub!(EMOJI_PATTERN) do |match| if valid_emoji?($2) @@ -106,8 +118,6 @@ module Gitlab match end end - - text end # Private: Checks if an emoji icon exists in the image asset directory |