An invalid `mailto` link in markdown caused an exception
Zendesk: https://gitlab.zendesk.com/agent/tickets/76098 (internal) Sentry: https://sentry.gitlap.com/gitlab/gitlabcom/issues/29898/ (internal)
A valid mailto
link should be in the format mailto:someone@example.com
. In case a user types an invalid mailto
link in a README.md, or another markdown file, Banzai will throw an exception and a 500 error occurs. An example of an invalid link is [my mail to link](mailto://someone@example.com)
The exception is:
URI::InvalidComponentError: missing opaque part for mailto URL
from uri/mailto.rb:143:in `initialize'
from uri/rfc3986_parser.rb:76:in `new'
from uri/rfc3986_parser.rb:76:in `parse'
from uri/common.rb:227:in `parse'
from lib/banzai/filter/external_link_filter.rb:26:in `uri'
from lib/gitlab/metrics/instrumentation.rb:156:in `block in uri'
from lib/gitlab/metrics/method_call.rb:23:in `measure'
from lib/gitlab/metrics/instrumentation.rb:156:in `uri'
from lib/banzai/filter/external_link_filter.rb:9:in `block in call'
from nokogiri/xml/node_set.rb:187:in `block in each'
from nokogiri/xml/node_set.rb:186:in `upto'
from nokogiri/xml/node_set.rb:186:in `each'
from lib/banzai/filter/external_link_filter.rb:8:in `call'
from lib/gitlab/metrics/instrumentation.rb:156:in `block in call'
from lib/gitlab/metrics/method_call.rb:23:in `measure'
from lib/gitlab/metrics/instrumentation.rb:156:in `call'
from html/pipeline/filter.rb:137:in `call'
from html/pipeline.rb:121:in `block in perform_filter'
from html/pipeline.rb:159:in `instrument'
from html/pipeline.rb:120:in `perform_filter'
from html/pipeline.rb:106:in `block (2 levels) in call'
from html/pipeline.rb:105:in `each'
from html/pipeline.rb:105:in `inject'
from html/pipeline.rb:105:in `block in call'
from html/pipeline.rb:159:in `instrument'
from html/pipeline.rb:103:in `call'
from lib/banzai/pipeline/base_pipeline.rb:21:in `block (2 levels) in singleton class'
snip...
We should catch URI::InvalidComponentError
and simply not process the link