Commit 17ac712c authored by Stan Hu's avatar Stan Hu

Merge branch '51233-process-urls-with-spaces-to-support-old-attachment-uploads-2' into 'master'

Resolve "Process urls with spaces in all markdown processing"

Closes #51233

See merge request gitlab-org/gitlab-ce!21602
parents 6d1b5850 1d478547
...@@ -10,11 +10,12 @@ module Banzai ...@@ -10,11 +10,12 @@ module Banzai
# #
# CommonMark does not allow spaces in the url portion of a link/url. # CommonMark does not allow spaces in the url portion of a link/url.
# For example, `[example](page slug)` is not valid. # For example, `[example](page slug)` is not valid.
# Neither is `![example](test image.jpg)`. However, # Neither is `![example](test image.jpg)`. However, particularly
# in our wikis, we support (via RedCarpet) this type of link, allowing # in our wikis, we support (via RedCarpet) this type of link, allowing
# wiki pages to be easily linked by their title. This filter adds that functionality. # wiki pages to be easily linked by their title. This filter adds that functionality.
# The intent is for this to only be used in Wikis - in general, we want #
# to adhere to CommonMark's spec. # This is a small extension to the CommonMark spec. If they start allowing
# spaces in urls, we could then remove this filter.
# #
class SpacedLinkFilter < HTML::Pipeline::Filter class SpacedLinkFilter < HTML::Pipeline::Filter
include ActionView::Helpers::TagHelper include ActionView::Helpers::TagHelper
......
...@@ -16,6 +16,7 @@ module Banzai ...@@ -16,6 +16,7 @@ module Banzai
Filter::MathFilter, Filter::MathFilter,
Filter::ColorFilter, Filter::ColorFilter,
Filter::MermaidFilter, Filter::MermaidFilter,
Filter::SpacedLinkFilter,
Filter::VideoLinkFilter, Filter::VideoLinkFilter,
Filter::ImageLazyLoadFilter, Filter::ImageLazyLoadFilter,
Filter::ImageLinkFilter, Filter::ImageLinkFilter,
......
...@@ -5,7 +5,6 @@ module Banzai ...@@ -5,7 +5,6 @@ module Banzai
@filters ||= begin @filters ||= begin
super.insert_after(Filter::TableOfContentsFilter, Filter::GollumTagsFilter) super.insert_after(Filter::TableOfContentsFilter, Filter::GollumTagsFilter)
.insert_before(Filter::TaskListFilter, Filter::WikiLinkFilter) .insert_before(Filter::TaskListFilter, Filter::WikiLinkFilter)
.insert_before(Filter::VideoLinkFilter, Filter::SpacedLinkFilter)
end end
end end
end end
......
...@@ -184,7 +184,7 @@ describe IssuablesHelper do ...@@ -184,7 +184,7 @@ describe IssuablesHelper do
issuableRef: "##{issue.iid}", issuableRef: "##{issue.iid}",
markdownPreviewPath: "/#{@project.full_path}/preview_markdown", markdownPreviewPath: "/#{@project.full_path}/preview_markdown",
markdownDocsPath: '/help/user/markdown', markdownDocsPath: '/help/user/markdown',
markdownVersion: 11, markdownVersion: CacheMarkdownField::CACHE_COMMONMARK_VERSION,
issuableTemplates: [], issuableTemplates: [],
projectPath: @project.path, projectPath: @project.path,
projectNamespace: @project.namespace.path, projectNamespace: @project.namespace.path,
......
...@@ -87,4 +87,22 @@ describe Banzai::Pipeline::GfmPipeline do ...@@ -87,4 +87,22 @@ describe Banzai::Pipeline::GfmPipeline do
end end
end end
end end
describe 'markdown link or image urls having spaces' do
let(:project) { create(:project, :public) }
it 'rewrites links with spaces in url' do
markdown = "[Link to Page](page slug)"
output = described_class.to_html(markdown, project: project)
expect(output).to include("href=\"page%20slug\"")
end
it 'rewrites images with spaces in url' do
markdown = "![My Image](test image.png)"
output = described_class.to_html(markdown, project: project)
expect(output).to include("src=\"test%20image.png\"")
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment