Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
3ecc4df4
Commit
3ecc4df4
authored
Sep 13, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1456 from tsigo/issue_1308
Fix HTML entities being parsed in GFM
parents
85def2d6
d993f666
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
6 deletions
+17
-6
lib/gitlab/markdown.rb
lib/gitlab/markdown.rb
+16
-6
spec/helpers/gitlab_markdown_helper_spec.rb
spec/helpers/gitlab_markdown_helper_spec.rb
+1
-0
No files found.
lib/gitlab/markdown.rb
View file @
3ecc4df4
...
@@ -26,13 +26,13 @@ module Gitlab
...
@@ -26,13 +26,13 @@ module Gitlab
# => "<img alt=\":trollface:\" class=\"emoji\" src=\"/images/trollface.png" title=\":trollface:\" />
# => "<img alt=\":trollface:\" class=\"emoji\" src=\"/images/trollface.png" title=\":trollface:\" />
module
Markdown
module
Markdown
REFERENCE_PATTERN
=
%r{
REFERENCE_PATTERN
=
%r{
(
[^
\w
&;])?
# Prefix (1)
(
\W
)?
# Prefix (1)
( # Reference (2)
( # Reference (2)
@([
\w\.
_]+) # User name (3)
@([
\w\.
_]+) # User name (3)
|[#!$](
\d
+) # Issue/MR/Snippet ID (4)
|[#!$](
\d
+) # Issue/MR/Snippet ID (4)
|([
\h
]{6,40}) # Commit ID (5)
|([
\h
]{6,40}) # Commit ID (5)
)
)
(
[^
\w
&;])?
# Suffix (6)
(
\W
)?
# Suffix (6)
}x
.
freeze
}x
.
freeze
EMOJI_PATTERN
=
%r{(:(
\S
+):)}
.
freeze
EMOJI_PATTERN
=
%r{(:(
\S
+):)}
.
freeze
...
@@ -84,6 +84,13 @@ module Gitlab
...
@@ -84,6 +84,13 @@ module Gitlab
#
#
# Returns parsed text
# Returns parsed text
def
parse
(
text
)
def
parse
(
text
)
parse_references
(
text
)
if
@project
parse_emoji
(
text
)
text
end
def
parse_references
(
text
)
# parse reference links
# parse reference links
text
.
gsub!
(
REFERENCE_PATTERN
)
do
|
match
|
text
.
gsub!
(
REFERENCE_PATTERN
)
do
|
match
|
prefix
=
$1
||
''
prefix
=
$1
||
''
...
@@ -91,13 +98,18 @@ module Gitlab
...
@@ -91,13 +98,18 @@ module Gitlab
identifier
=
$3
||
$4
||
$5
identifier
=
$3
||
$4
||
$5
suffix
=
$6
||
''
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
prefix
+
ref_link
+
suffix
else
else
match
match
end
end
end
if
@project
end
end
def
parse_emoji
(
text
)
# parse emoji
# parse emoji
text
.
gsub!
(
EMOJI_PATTERN
)
do
|
match
|
text
.
gsub!
(
EMOJI_PATTERN
)
do
|
match
|
if
valid_emoji?
(
$2
)
if
valid_emoji?
(
$2
)
...
@@ -106,8 +118,6 @@ module Gitlab
...
@@ -106,8 +118,6 @@ module Gitlab
match
match
end
end
end
end
text
end
end
# Private: Checks if an emoji icon exists in the image asset directory
# Private: Checks if an emoji icon exists in the image asset directory
...
...
spec/helpers/gitlab_markdown_helper_spec.rb
View file @
3ecc4df4
...
@@ -31,6 +31,7 @@ describe GitlabMarkdownHelper do
...
@@ -31,6 +31,7 @@ describe GitlabMarkdownHelper do
end
end
it
"should not touch HTML entities"
do
it
"should not touch HTML entities"
do
@project
.
issues
.
stub
(
:where
).
with
(
id:
'39'
).
and_return
([
issue
])
actual
=
expected
=
"We'll accept good pull requests."
actual
=
expected
=
"We'll accept good pull requests."
gfm
(
actual
).
should
==
expected
gfm
(
actual
).
should
==
expected
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment