diff options
Diffstat (limited to 'lib/rubygems/server.rb')
-rw-r--r-- | lib/rubygems/server.rb | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/rubygems/server.rb b/lib/rubygems/server.rb index 212ccc5f7e..ed957dd38a 100644 --- a/lib/rubygems/server.rb +++ b/lib/rubygems/server.rb @@ -368,19 +368,34 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } when '/quick/index.rz' then index = @source_index.map { |name,_| name }.join("\n") res.body << Zlib::Deflate.deflate(index) - when %r|^/quick/(.*)-([0-9.]+)\.gemspec(\.marshal)?\.rz$| then - specs = @source_index.search $1, $2 + when %r|^/quick/(Marshal.#{Regexp.escape Gem.marshal_version}/)?(.*?)-([0-9.]+)(-.*?)?\.gemspec\.rz$| then + dep = Gem::Dependency.new $2, $3 + specs = @source_index.search dep + + selector = [$2, $3, $4].map { |s| s.inspect }.join ' ' + + platform = if $4 then + Gem::Platform.new $4.sub(/^-/, '') + else + Gem::Platform::RUBY + end + + specs = specs.select { |s| s.platform == platform } + if specs.empty? then res.status = 404 + res.body = "No gems found matching #{selector}" elsif specs.length > 1 then res.status = 500 - elsif $3 # marshal quickindex instead of YAML + res.body = "Multiple gems found matching #{selector}" + elsif $1 then # marshal quickindex instead of YAML res.body << Zlib::Deflate.deflate(Marshal.dump(specs.first)) else # deprecated YAML format res.body << Zlib::Deflate.deflate(specs.first.to_yaml) end else res.status = 404 + res.body = "#{req.request_uri} not found" end end |