Hi,
We received the following bug report in the Debian BTS for Barby:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=557023
> Creating a new instance of Barby::Code128 with a legitimate string can
> cause a stack trace. One such string is the empty string:
>
> Barby::Code128.new("", 'B')
>
> The stack trace is:
>
> /usr/lib/ruby/1.8/barby/barcode/code_128.rb:239:in `characters': private method `split' called for ni
l:NilClass (NoMethodError)
> from /usr/lib/ruby/1.8/barby/barcode/code_128.rb:364
:in `valid?'
> from /usr/lib/ruby/1.8/barby/barcode/code_128.rb:162
:in `initialize'
> from ./foo.rb:15:in `new'
> from ./foo.rb:15
>
> foo.rb (attached) reproduces the problem two different ways.
The submitter supplied two patches fixing this problem (the second one
fixing a case he didn't originally consider) - I'm inlining them both
here:
diff -ur libbarby-ruby-0.3.orig/lib/barby/barcode/code_128.rb libbarby-
ruby-0.3/lib/barby/barcode/code_128.rb
--- libbarby-ruby-0.3.orig/lib/barby/barcode/code_128.rb
2009-11-18 17:51:28.000000000 -0700
+++ libbarby-ruby-0.3/lib/barby/barcode/code_128.rb
2009-11-18 17:51:37.000000000 -0700
@@ -227,8 +227,8 @@
#sets, in which case the extra will itself have an extra.
def extra=(extra)
raise ArgumentError, "Extra must begin with \\301, \\302 or \
\303" unless extra =~ /^[#{CODEA+CODEB+CODEC}]/n
- type = extra[/([#{CODEA+CODEB+CODEC}])/n, 1]
- data = extra[/[#{CODEA+CODEB+CODEC}](.*)/n, 1]
+ type = extra[0..0]
+ data = extra[1..-1]
@extra = class_for(type).new(data)
end
diff -ur libbarby-ruby-0.3.orig/lib/barby/barcode/code_128.rb libbarby-
ruby-0.3/lib/barby/barcode/code_128.rb
--- libbarby-ruby-0.3.orig/lib/barby/barcode/code_128.rb
2009-11-18 17:51:28.000000000 -0700
+++ libbarby-ruby-0.3/lib/barby/barcode/code_128.rb
2009-11-18 22:35:54.000000000 -0700
@@ -208,7 +208,7 @@
#character set, an extra will be created.
def data=(data)
data, *extra = data.split(/([#{CODEA+CODEB+CODEC}])/n)
- @data = data
+ @data = data || ''
self.extra = extra.join unless extra.empty?
end
Thank you,
--
Gunnar Wolf •
gw...@gwolf.org •
(+52-55)5623-0154 / 1451-2244