Commit d37fa9db authored by Stan Hu's avatar Stan Hu Committed by Robert Speicher

Merge branch '18819-wiki-link-filter-exception' into 'master'

Fix bug in `WikiLinkFilter`.

Closes #18819

- [ ]  #18819 Wiki link filter exception
    - [x]  Make sure [build](https://gitlab.com/gitlab-org/gitlab-ce/commit/6d169d36cabda783116bcb8e2e6f73254566a670/builds) passes
    - [ ]  Wait for merge
    - [ ]  Pick into 8.9

See merge request !4775
parent a767bb46
...@@ -16,6 +16,7 @@ v 8.9.1 (unreleased) ...@@ -16,6 +16,7 @@ v 8.9.1 (unreleased)
- Fix typo in export failure email. !4847 - Fix typo in export failure email. !4847
- Fix header vertical centering. !4170 - Fix header vertical centering. !4170
- Fix subsequent SAML sign ins. !4718 - Fix subsequent SAML sign ins. !4718
- Prevent invalid URLs from raising exceptions in WikiLink Filter. !4775
v 8.9.0 v 8.9.0
- Fix builds API response not including commit data - Fix builds API response not including commit data
......
...@@ -29,7 +29,7 @@ module Banzai ...@@ -29,7 +29,7 @@ module Banzai
return if html_attr.blank? return if html_attr.blank?
html_attr.value = apply_rewrite_rules(html_attr.value) html_attr.value = apply_rewrite_rules(html_attr.value)
rescue URI::Error rescue URI::Error, Addressable::URI::InvalidURIError
# noop # noop
end end
......
require 'spec_helper'
describe Banzai::Filter::WikiLinkFilter, lib: true do
include FilterSpecHelper
let(:namespace) { build_stubbed(:namespace, name: "wiki_link_ns") }
let(:project) { build_stubbed(:empty_project, :public, name: "wiki_link_project", namespace: namespace) }
let(:user) { double }
let(:wiki) { ProjectWiki.new(project, user) }
it "doesn't rewrite absolute links" do
filtered_link = filter("<a href='http://example.com:8000/'>Link</a>", project_wiki: wiki).children[0]
expect(filtered_link.attribute('href').value).to eq('http://example.com:8000/')
end
describe "invalid links" do
invalid_links = ["http://:8080", "http://", "http://:8080/path"]
invalid_links.each do |invalid_link|
it "doesn't rewrite invalid invalid_links like #{invalid_link}" do
filtered_link = filter("<a href='#{invalid_link}'>Link</a>", project_wiki: wiki).children[0]
expect(filtered_link.attribute('href').value).to eq(invalid_link)
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