mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-17 19:12:37 -05:00
FIX: proper hack to support underscores in URLs
This commit is contained in:
parent
e26e5312d7
commit
961f676b91
3 changed files with 12 additions and 17 deletions
4
Gemfile
4
Gemfile
|
@ -249,10 +249,6 @@ gem 'stringex', require: false
|
|||
|
||||
gem 'logster'
|
||||
|
||||
# we need that to support underscore in URLs (mostly when using S3 for storing files)
|
||||
# cf. http://stackoverflow.com/a/17108137/11983
|
||||
gem 'addressable'
|
||||
|
||||
# perftools only works on 1.9 atm
|
||||
group :profile do
|
||||
# travis refuses to install this, instead of fuffing, just avoid it for now
|
||||
|
|
|
@ -407,7 +407,6 @@ PLATFORMS
|
|||
DEPENDENCIES
|
||||
actionpack-action_caching
|
||||
active_model_serializers (~> 0.8.0)
|
||||
addressable
|
||||
annotate
|
||||
barber
|
||||
better_errors
|
||||
|
|
|
@ -1,15 +1,4 @@
|
|||
require "open-uri"
|
||||
require "addressable/uri"
|
||||
|
||||
class URI::Parser
|
||||
|
||||
# HACK to support underscores in URLs
|
||||
def split(url)
|
||||
a = Addressable::URI::parse(url)
|
||||
[a.scheme, a.userinfo, a.host, a.port, nil, a.path, nil, a.query, a.fragment]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class FileHelper
|
||||
|
||||
|
@ -20,7 +9,7 @@ class FileHelper
|
|||
def self.download(url, max_file_size, tmp_file_name, follow_redirect=false)
|
||||
raise Discourse::InvalidParameters.new(:url) unless url =~ /^https?:\/\//
|
||||
|
||||
uri = URI.parse(url)
|
||||
uri = parse_url(url)
|
||||
extension = File.extname(uri.path)
|
||||
tmp = Tempfile.new([tmp_file_name, extension])
|
||||
|
||||
|
@ -46,4 +35,15 @@ class FileHelper
|
|||
@@images_regexp ||= /\.(#{images.to_a.join("|")})$/i
|
||||
end
|
||||
|
||||
# HACK to support underscores in URLs
|
||||
# cf. http://stackoverflow.com/a/18938253/11983
|
||||
def self.parse_url(url)
|
||||
URI.parse(url)
|
||||
rescue URI::InvalidURIError
|
||||
host = url.match(".+\:\/\/([^\/]+)")[1]
|
||||
uri = URI.parse(url.sub(host, 'valid-host'))
|
||||
uri.instance_variable_set("@host", host)
|
||||
uri
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue