jarrett / rbbcode

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

Nested Quotes -> undefined method 'elements' on nilclass #13

Closed PeteMichaud closed 11 years ago

PeteMichaud commented 11 years ago

This one has me scratching my head.

I added a complex_blockquote to rbbcode (https://github.com/PeteMichaud/rbbcode/tree/pete), and discovered that nesting them gave me this error:

RbbCode.new.convert("[quote=Pete Michaud]\n[quote=Author]This is a quote[/quote]\n\n[quote=Another Author]This is a [b]quote[/b][/quote]\n[/quote]")

#=> NameError: undefined local variable or method `elements' for nil:NilClass

So I tracked that error down to https://github.com/PeteMichaud/rbbcode/blob/pete/lib/rbbcode/node_extensions.rb#L32 where elements is called.

I'm really confused because apparently self.elements is failing because self is nil.

I thought maybe it was my fault and there was something wrong with the grammar for complex_quote, so I poked around and discovered that nesting any kind quote hase the same result:

RbbCode.new.convert("[quote][quote]This is a quote[/quote][/quote]")

#=> NameError: undefined local variable or method `elements' for nil:NilClass 

These both work fine:

RbbCode.new.convert("[b][i]Text[/i][/b]")

RbbCode.new.convert("[i][i]Text[/i][/i]")

But I noticed that url doesn't parse recursively:

RbbCode.new.convert("[url=testing][i]This is a quote[/i][/url]")
#=> "\n<p><a href=\"testing\">[i]This is a quote[/i]</a></p>" 

So I thought maybe I could produce the same error by changing https://github.com/PeteMichaud/rbbcode/blob/pete/lib/rbbcode/node_extensions.rb#L73 to:

'<a href="' + url.text_value + '">' + recursively_convert(text) + '</a>'

But it doesn't produce an error. Apparently in that context recursively_convert("[i]Text[/i]") => "[i]Text[/i]"

I don't get it, I'm lost. What do you think?

jarrett commented 11 years ago

Can you give me a full stack trace?

On Thu, Nov 15, 2012 at 1:17 AM, Pete Michaud notifications@github.comwrote:

This one has me scratching my head.

I added a complex_blockquote to rbbcode ( https://github.com/PeteMichaud/rbbcode/tree/pete), and discovered that nesting them gave me this error:

RbbCode.new.convert("[quote=Pete Michaud]\n[quote=Author]This is a quote[/quote]\n\n[quote=Another Author]This is a [b]quote[/b][/quote]\n[/quote]")

=> NameError: undefined local variable or method `elements' for nil:NilClass

So I tracked that error down to https://github.com/PeteMichaud/rbbcode/blob/pete/lib/rbbcode/node_extensions.rb#L32where elements is called.

I'm really confused because apparently self.elements is failing because self is nil.

I thought maybe it was my fault and there was something wrong with the grammar for complex_quote, so I poked around and discovered that nesting any kind quote hase the same result:

RbbCode.new.convert("[quote][quote]This is a quote[/quote][/quote]")

=> NameError: undefined local variable or method `elements' for nil:NilClass

These both work fine:

RbbCode.new.convert("[b][i]Text[/i][/b]")

RbbCode.new.convert("[i][i]Text[/i][/i]")

But I noticed that url doesn't parse recursively:

RbbCode.new.convert("[url=testing][i]This is a quote[/i][/url]")

=> "\n

<a href=\"testing\">[i]This is a quote[/i]

"

So I thought maybe I could produce the same error by changing https://github.com/PeteMichaud/rbbcode/blob/pete/lib/rbbcode/node_extensions.rb#L73to:

'' + recursively_convert(text) + ''

But it doesn't produce an error. Apparently in that context recursively_convert("[i]Text[/i]") => "[i]Text[/i]"

I don't get it, I'm lost. What do you think?

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

PeteMichaud commented 11 years ago

I'm afraid it's not particularly helpful:

1.9.3p194 :001 > RbbCode.new.convert("[quote][quote]Test[/quote][/quote]")
NameError: undefined local variable or method `elements' for nil:NilClass
from /Users/pete/Projects/rbbcode/lib/rbbcode/node_extensions.rb:32:in `to_html'
from /Users/pete/Projects/rbbcode/lib/rbbcode.rb:37:in `convert'
from (irb):1
from /Users/pete/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in `start'
from /Users/pete/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in `start'
from /Users/pete/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
jarrett commented 11 years ago

Can you verify that Treetop is actually extending nil with the ParagraphNode module?

On Fri, Nov 16, 2012 at 2:33 PM, Pete Michaud notifications@github.comwrote:

I'm afraid it's not particularly helpful:

1.9.3p194 :001 > RbbCode.new.convert("[quote][quote]Test[/quote][/quote]") NameError: undefined local variable or method elements' for nil:NilClass from /Users/pete/Projects/rbbcode/lib/rbbcode/node_extensions.rb:32:into_html' from /Users/pete/Projects/rbbcode/lib/rbbcode.rb:37:in convert' from (irb):1 from /Users/pete/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands/console.rb:47:instart' from /Users/pete/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in start' from /Users/pete/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:41:in<top (required)>' from script/rails:6:in require' from script/rails:6:in

'

— Reply to this email directly or view it on GitHubhttps://github.com/jarrett/rbbcode/issues/13#issuecomment-10461129.

PeteMichaud commented 11 years ago

I'm not sure where to find that -- the only extend I can see in the code is in TagNode where it extends itself if t is a Module. By teh way, are you able to reproduce this bug?

jarrett commented 11 years ago

Sorry, I'm super swamped right now, which is why I'm just giving rough ideas about debugging instead of trying to solve it myself. So here's another idea: Try to produce the simplest possible failing case. Strip away as much of the Treetop grammar and node extensions as you can without making the bug disappear. If I can see a minimal example of the failure, I might have an idea of what it is.

On Fri, Nov 16, 2012 at 3:26 PM, Pete Michaud notifications@github.comwrote:

I'm not sure where to find that -- the only extend I can see in the code is in TagNode where it extends itself if t is a Module. By teh way, are you able to reproduce this bug?

— Reply to this email directly or view it on GitHubhttps://github.com/jarrett/rbbcode/issues/13#issuecomment-10462819.

jarrett commented 11 years ago

Hi there. I haven't heard anything on this ticket in a while, so I'm hoping you've successfully resolved it. I'll close it for now. Sorry I couldn't be more help. While I do plan to keep rbbcode maintained, unfortunately I don't have enough free time to help with forks except to give general advice and ideas.