FIX: URLs containing two # would fail to work

Some URLs in browsers are non compliant and contain twos `#` this commit adds
special handling for this edge case by auto encoding any fragments containing `#`
This commit is contained in:
Sam
2018-12-11 18:03:13 +11:00
parent bb4ef644bf
commit 671469bcc7
6 changed files with 47 additions and 26 deletions

View File

@@ -1,5 +1,20 @@
class UrlHelper
# At the moment this handles invalid URLs that browser address bar accepts
# where second # is not encoded
#
# Longer term we can add support of simpleidn and encode unicode domains
def self.relaxed_parse(url)
url, fragment = url.split("#", 2)
uri = URI.parse(url)
if uri
fragment = URI.escape(fragment) if fragment&.include?('#')
uri.fragment = fragment
uri
end
rescue URI::Error
end
def self.is_local(url)
url.present? && (
Discourse.store.has_been_uploaded?(url) ||