的是一些代码,我继承和它应该从URL中移除参数,但它与下面的错误打破:不知道这是什么红宝石方法做如下方法
ArgumentError: the input of URI.decode_www_form must be ASCII only string /home/fatman/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/uri/common.rb:969:in `decode_www_form'
def self.removeUnnecessaryGetParams(url, removeParams = ["s"], whiteListParams = nil)
uri = Addressable::URI.parse(url)
#Get rid of UTM parameters & S parameters
if(uri.query != nil)
if(whiteListParams != nil)
cleanKeyVals = URI.decode_www_form(uri.query).reject{|k, _| !whiteListParams.include?(k)}
else
cleanKeyVals = URI.decode_www_form(uri.query).reject{|k, _| k.start_with?("utm_") or removeParams.include?(k)}
end
uri.query = URI.encode_www_form(cleanKeyVals)
end
return uri.to_s.split("#")[0].chomp("?")
end
1)。我的问题是,这种方法究竟是如何工作的?不知道线路正在做什么,分配给cleankeyVals
(我的红宝石知识缺点)。 2)。如何解决这个只有ASCII字符串的问题?
你看过导致此错误的字符串?你试图显然给它非ASCII字符。 – Carcigenicate
命名约定,使用'!= nil'和其他怪癖表明这不是由真正获得Ruby的人写的。如果有机会,也值得更新Ruby。保持最新以避免安全问题。 – tadman