kr/okjson — Issue #5: NoMethodError decoding the string 'foo'
Author: csquared
Created: 2012-03-09 00:06:09+00:00
State: open

This is a weird one, but I only get this error decoding the string "foo". I get a NoMethodError instead of the expected OkJson::Error. This is super weird. Remembering our game at Tahoe, I tried out a couple of variations and think it has to do with beginning with the character 'f'. Which makes this not just weird, but "f"-ing weird.

Reproducible in ruby 1.8.7 and 1.9.3.

1.8.7-p352 :004 > OkJson.decode 'foo'
NoMethodError: undefined method `length' for nil:NilClass
from ./lib/heroku/kensa/okjson.rb:182:in `lex'
from ./lib/heroku/kensa/okjson.rb:43:in `decode'
from (irb):4

1.9.3p0 :003 > OkJson.decode 'foo'
NoMethodError: undefined method `length' for nil:NilClass
from /Users/csquared/heroku/kensa/lib/heroku/kensa/okjson.rb:182:in `lex'
from /Users/csquared/heroku/kensa/lib/heroku/kensa/okjson.rb:43:in `decode'
from (irb):3
from /Users/csquared/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in `

'

1.9.3p0 :013 > OkJson.decode 'fo'
NoMethodError: undefined method `length' for nil:NilClass
from /Users/csquared/heroku/kensa/lib/heroku/kensa/okjson.rb:182:in `lex'
from /Users/csquared/heroku/kensa/lib/heroku/kensa/okjson.rb:43:in `decode'
from (irb):13
from /Users/csquared/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in `

' 1.9.3p0 :014 > OkJson.decode 'f' NoMethodError: undefined method `length' for nil:NilClass
from /Users/csquared/heroku/kensa/lib/heroku/kensa/okjson.rb:182:in `lex'
from /Users/csquared/heroku/kensa/lib/heroku/kensa/okjson.rb:43:in `decode'
from (irb):14
from /Users/csquared/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in `

'
1.9.3p0 :015 > OkJson.decode 'ff'
NoMethodError: undefined method `length' for nil:NilClass
from /Users/csquared/heroku/kensa/lib/heroku/kensa/okjson.rb:182:in `lex'
from /Users/csquared/heroku/kensa/lib/heroku/kensa/okjson.rb:43:in `decode'
from (irb):15
from /Users/csquared/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in `

'
1.9.3p0 :016 > OkJson.decode 'd'
OkJson::Error: invalid character at "d"
from /Users/csquared/heroku/kensa/lib/heroku/kensa/okjson.rb:177:in `lex'
from /Users/csquared/heroku/kensa/lib/heroku/kensa/okjson.rb:43:in `decode'
from (irb):16
from /Users/csquared/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in `

'