mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
@@ -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) ||
|
||||
|
||||
Reference in New Issue
Block a user