-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[frontend] Fix rendering invalid markdown links
Since commit c466c65 we overwrite the redcarpet renderer for links and add the OBS domain to relative links. The code that would craft these URIs wasn't expecting invalid links and would fail with an URI::InvalidURIError exception. This commit catches such exceptions and renders the invalid markdown in the same format Redcarpet would do.
- Loading branch information
Showing
2 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe CommentHelper, type: :helper do | ||
describe '#comment_body' do | ||
it 'renders markdown links to html links' do | ||
expect(comment_body('[my link](https://github.com/openSUSE/open-build-service/issues/5091)')).to eq( | ||
"<p><a href='https://github.com/openSUSE/open-build-service/issues/5091'>my link</a></p>\n" | ||
) | ||
end | ||
|
||
it 'adds the OBS domain to relative links' do | ||
expect(comment_body('[my link](/here)')).to eq( | ||
"<p><a href='#{::Configuration.obs_url}/here'>my link</a></p>\n" | ||
) | ||
end | ||
|
||
it 'does not crash due to invalid URIs' do | ||
expect(comment_body("anbox[400000+22d000]\r\n(the number)")).to eq( | ||
"<p>anbox<a href='the number'>400000+22d000</a></p>\n" | ||
) | ||
end | ||
end | ||
end |