jarrett / rbbcode

Converts BBCode to HTML. Gracefully handles invalid input. Built on Treetop.
41 stars 9 forks source link

Exception thrown when parsing invalid syntax #17

Closed dkharrat closed 11 years ago

dkharrat commented 11 years ago

I was trying your gem to parse bbcode and noticed that it crashed on certain user input. I stripped it down to:

[quote]this is [size]large text[/quote][/size]

This is what I get:

> text
 => "[quote]this is [size]large[/quote][/size]" 
> RbbCode.new.convert(text)
NameError: undefined local variable or method `elements' for nil:NilClass
    from /Users/dia/.rvm/gems/ruby-1.9.3-p125@testapp/gems/rbbcode-1.0.2/lib/rbbcode/node_extensions.rb:32:in `to_html'
    from /Users/dia/.rvm/gems/ruby-1.9.3-p125@testapp/gems/rbbcode-1.0.2/lib/rbbcode.rb:37:in `convert'
    from (irb):94
    from /Users/dia/.rvm/gems/ruby-1.9.3-p125@testapp/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
    from /Users/dia/.rvm/gems/ruby-1.9.3-p125@testapp/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
    from /Users/dia/.rvm/gems/ruby-1.9.3-p125@testapp/gems/railties-3.2.11/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

What's interesting is that for supported tags, it seems to work:

[quote]this is [b]large[/quote][/b]
> text = "[quote]this is [b]large[/quote][/b]"
 => "[quote]this is [b]large[/quote][/b]"
> RbbCode.new.convert(text)
 => "\n<p>[quote]this is <strong>large[/quote]</strong></p>" 

I would expect the first input to work similarly. Although, the syntax is incorrect, at least it shouldn't crash. The output of the second example is a reasonable one.

jarrett commented 11 years ago

Thanks! I'll check this out soon.

On Tue, Apr 2, 2013 at 3:16 AM, Dia Kharrat notifications@github.comwrote:

I was trying your gem to parse bbcode and noticed that it crashed on certain user input. I stripped it down to:

[quote]this is [size]large text[/quote][/size]

This is what I get:

text => "[quote]this is [size]large[/quote][/size]" RbbCode.new.convert(text) NameError: undefined local variable or method elements' for nil:NilClass from /Users/dia/.rvm/gems/ruby-1.9.3-p125@devmaster/gems/rbbcode-1.0.2/lib/rbbcode/node_extensions.rb:32:into_html' from /Users/dia/.rvm/gems/ruby-1.9.3-p125@devmaster/gems/rbbcode-1.0.2/lib/rbbcode.rb:37:in convert' from (irb):94 from /Users/dia/.rvm/gems/ruby-1.9.3-p125@devmaster/gems/railties-3.2.11/lib/rails/commands/console.rb:47:instart' from /Users/dia/.rvm/gems/ruby-1.9.3-p125@devmaster/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in start' from /Users/dia/.rvm/gems/ruby-1.9.3-p125@devmaster/gems/railties-3.2.11/lib/rails/commands.rb:41:in<top (required)>' from script/rails:6:in require' from script/rails:6:in

'

What's interesting is that for supported tags, it seems to work:

[quote]this is [b]large[/quote][/b]

text = "[quote]this is [b]large[/quote][/b]" => "[quote]this is [b]large[/quote][/b]" RbbCode.new.convert(text) => "\n

[quote]this is large[/quote]

"

I would expect the first input to work similarly. Although, the syntax is incorrect, at least it shouldn't crash. The output of the second example is a reasonable one.

— Reply to this email directly or view it on GitHubhttps://github.com/jarrett/rbbcode/issues/17 .

jarrett commented 11 years ago

Sorry this took so long. I've pushed a fix to the master branch. I want to release version 1.0.3 with this fix, but for whatever reason, pushing to rubygems.org is failing right now. I'll keep trying to release the new version. In the meantime, you can manually install 1.0.3 with the following steps:

  1. Clone the repo, or pull the latest if you've already cloned
  2. cd to the project root
  3. rake build
  4. rake install
dkharrat commented 11 years ago

Awesome, thanks for fixing it!

jarrett commented 11 years ago

Ok, I was finally able to release 1.0.3 on Rubygems.