FIX: Onebox fails on encoded URL.

https://meta.discourse.org/t/onebox-breaks-if-theres-chinese-text-in-url/67364
This commit is contained in:
Guo Xiang Tan
2017-09-26 18:34:54 +08:00
parent a324a8a9d4
commit 367fb1c524
3 changed files with 19 additions and 5 deletions

View File

@@ -30,8 +30,10 @@ class TopicEmbed < ActiveRecord::Base
# Prevents double URL encode
# https://stackoverflow.com/a/37599235
def self.escape_uri(uri)
URI.encode(uri).gsub(DOUBLE_ESCAPED_EXPR, '%\1')
def self.escape_uri(uri, pattern = URI::UNSAFE)
encoded = URI.encode(uri, pattern)
encoded.gsub!(DOUBLE_ESCAPED_EXPR, '%\1')
encoded
end
# Import an article from a source (RSS/Atom/Other)