From 09a8639482db1e01a6a749a496f8abb56736f830 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 11 Oct 2019 14:22:34 -0700 Subject: [PATCH] Fixed bug in Ruby DSL when no names are defined in a file. --- ruby/lib/google/protobuf.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/ruby/lib/google/protobuf.rb b/ruby/lib/google/protobuf.rb index 3aef07937f..83ece4cfa1 100644 --- a/ruby/lib/google/protobuf.rb +++ b/ruby/lib/google/protobuf.rb @@ -56,15 +56,19 @@ else module Internal def self.infer_package(names) # Package is longest common prefix ending in '.', if any. - min, max = names.minmax - last_common_dot = nil - min.size.times { |i| - if min[i] != max[i] then break end - if min[i] == ?. then last_common_dot = i end - } - if last_common_dot - return min.slice(0, last_common_dot) + if not names.empty? + min, max = names.minmax + last_common_dot = nil + min.size.times { |i| + if min[i] != max[i] then break end + if min[i] == ?. then last_common_dot = i end + } + if last_common_dot + return min.slice(0, last_common_dot) + end end + + nil end class NestingBuilder