Skip to content

Commit

Permalink
Prevent exception on empty URL in markdown text
Browse files Browse the repository at this point in the history
An empty URL part in markdown text leads to an exception
in the mardown renderer. When a comment
includes such an empty URL string, it ends up with a
code 500. This happens when people post code examples
which contain the same syntax as a markdown link.
Instead of throwing an exception, we can just render
the original content incase of an empty URL part.

Kudos to @eduardoj

Fixes #10259
  • Loading branch information
krauselukas committed Oct 9, 2020
1 parent 3e14a78 commit f296385
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/api/lib/obsapi/markdown_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def block_html(raw_html)

# unfortunately we can't call super (into C) - see vmg/redcarpet#51
def link(link, title, content)
# A return value of nil will not output any data
# the contents of the span will be copied verbatim
return nil if link.blank?

title = " title='#{title}'" if title.present?
begin
link = URI.join(::Configuration.obs_url, link)
Expand Down
6 changes: 6 additions & 0 deletions src/api/spec/helpers/webui/markdown_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,11 @@
"<p><a href=\"https://build.opensuse.org\">&amp;lt;script&amp;gt;&amp;lt;/script&amp;gt;</a></p>\n"
)
end

it 'just returns the original content on empty URIs' do
expect(render_as_markdown('installed_ver = self.core.version_func[deps_info[6]]()')).to eq(
"<p>installed_ver = self.core.version_func[deps_info[6]]()</p>\n"
)
end
end
end

0 comments on commit f296385

Please sign in to comment.