Skip to content

Commit

Permalink
Merge pull request seomoz#2 from seomoz/fix_max_url_length
Browse files Browse the repository at this point in the history
Check max URL length before URL encoding, instead of after.
  • Loading branch information
evanbattaglia committed Jul 20, 2011
2 parents bda444c + 4342b58 commit a69cf60
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/linkscape/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ def initialize(options)
if options[:url]
case options[:url]
when String
if options[:url].length > MAX_URL_LENGTH
raise ArgumentError.new("Request URLs must be < #{MAX_URL_LENGTH} long")
end
new_vals = {:url => CGI::escape(options[:url].sub(/^https?:\/\//, '')) }
when Array
@body = options[:url].collect{ |u| u.sub(/^https?:\/\//, '') }
Expand All @@ -31,10 +34,6 @@ def initialize(options)
end
end

if Array(new_vals[:url]).any? { |u| u.length > MAX_URL_LENGTH }
raise ArgumentError.new("Request URLs must be < #{MAX_URL_LENGTH} long")
end

@requestURL = URL_TEMPLATE.template(signRequest(options.merge(new_vals)))
@requestURL += "&" + options[:query].collect{|k,v| "#{CGI::escape(k.to_s)}=#{CGI::escape(v.to_s)}"}.join('&') if options[:query] && Hash === options[:query]
@requestURL += "&" + options[:query] if options[:query] && String === options[:query]
Expand Down

0 comments on commit a69cf60

Please sign in to comment.