Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixed deprecated method call in list parser #30

Closed
wants to merge 1 commit into from

2 participants

@marxjohnson

The current code produces a deprecated warning in Ruby 1.8 and fails in Ruby 1.9 when parsing a definition list. This is due to use of a .type method. I've changed this to .class which fixes the problem.

@gettalong gettalong was assigned
@gettalong
Owner

This should be no bug, this just uses the Element#type accessor. I always run the tests under Ruby 1.8. and 1.9 and I don't get a warning or a failure.

How did you test? What Ruby versions? What OS?

@gettalong
Owner

Okay, after some more thinking why this could happen I have a test case which triggers a NoMethodError under Ruby 1.9:

test
: 

hallo
: test

The problem is not that there should be .class instead of .type but that the it.children is empty. Will have to investigate a bit more and then fix it.

Thanks for reporting this!

@marxjohnson

Sorry, I should really have filed a proper bug report first, I got over-excited.

Running Ubuntu 12.04, Ruby 1.8.7, using kramdown 0.14.0 through jekyll, I get this warning:

/home/mark-work/.rvm/gems/ruby-1.8.7-p371/gems/kramdown-0.14.0/lib/kramdown/parser/kramdown/list.rb:217: warning: Object#type is deprecated; use Object#class

With Ruby 1.9.3, it crashes thusly:

   /home/mark-work/.rvm/gems/ruby-1.9.3-p327/gems/kramdown-0.14.0/lib/kramdown/parser/kramdown/list.rb:217:in   'block in parse_definition_list': undefined method 'type' for nil:NilClass (NoMethodError)
    from /home/mark-work/.rvm/gems/ruby-1.9.3-p327/gems/kramdown-0.14.0/lib/kramdown/parser/kramdown/list.rb:205:in 'each'
    from /home/mark-work/.rvm/gems/ruby-1.9.3-p327/gems/kramdown-0.14.0/lib/kramdown/parser/kramdown/list.rb:205:in 'parse_definition_list'
    from /home/mark-work/.rvm/gems/ruby-1.9.3-p327/gems/kramdown-0.14.0/lib/kramdown/parser/kramdown.rb:140:in 'block (2 levels) in parse_blocks'
    from /home/mark-work/.rvm/gems/ruby-1.9.3-p327/gems/kramdown-0.14.0/lib/kramdown/parser/kramdown.rb:138:in 'each'
    from /home/mark-work/.rvm/gems/ruby-1.9.3-p327/gems/kramdown-0.14.0/lib/kramdown/parser/kramdown.rb:138:in 'any?'
    from /home/mark-work/.rvm/gems/ruby-1.9.3-p327/gems/kramdown-0.14.0/lib/kramdown/parser/kramdown.rb:138:in 'block in parse_blocks'
    from /home/mark-work/.rvm/gems/ruby-1.9.3-p327/gems/kramdown-0.14.0/lib/kramdown/parser/kramdown.rb:135:in 'catch'
    from /home/mark-work/.rvm/gems/ruby-1.9.3-p327/gems/kramdown-0.14.0/lib/kramdown/parser/kramdown.rb:135:in 'parse_blocks'
    from /home/mark-work/.rvm/gems/ruby-1.9.3-p327/gems/kramdown-0.14.0/lib/kramdown/parser/kramdown.rb:101:in 'parse'
    from /home/mark-work/.rvm/gems/ruby-1.9.3-p327/gems/kramdown-0.14.0/lib/kramdown/parser/base.rb:78:in 'parse'
    from /home/mark-work/.rvm/gems/ruby-1.9.3-p327/gems/kramdown-0.14.0/lib/kramdown/document.rb:119:in 'initialize'
    from /home/mark-work/.rvm/gems/ruby-1.9.3-p327/gems/jekyll-0.11.2/lib/jekyll/converters/markdown.rb:110:in 'new'
    from /home/mark-work/.rvm/gems/ruby-1.9.3-p327/gems/jekyll-0.11.2/lib/jekyll/converters/markdown.rb:110:in 'convert'
    from /home/mark-work/.rvm/gems/ruby-1.9.3-p327/gems/jekyll-0.11.2/lib/jekyll/convertible.rb:46:in 'transform'
    from /home/mark-work/.rvm/gems/ruby-1.9.3-p327/gems/jekyll-0.11.2/lib/jekyll/convertible.rb:84:in 'do_layout'
    from /home/mark-work/.rvm/gems/ruby-1.9.3-p327/gems/jekyll-0.11.2/lib/jekyll/page.rb:100:in 'render'
    from /home/mark-work/.rvm/gems/ruby-1.9.3-p327/gems/jekyll-0.11.2/lib/jekyll/site.rb:197:in 'block in render'
    from /home/mark-work/.rvm/gems/ruby-1.9.3-p327/gems/jekyll-0.11.2/lib/jekyll/site.rb:196:in 'each'
    from /home/mark-work/.rvm/gems/ruby-1.9.3-p327/gems/jekyll-0.11.2/lib/jekyll/site.rb:196:in 'render'
    from /home/mark-work/.rvm/gems/ruby-1.9.3-p327/gems/jekyll-0.11.2/lib/jekyll/site.rb:40:in 'process'
    from /home/mark-work/.rvm/gems/ruby-1.9.3-p327/gems/jekyll-0.11.2/bin/jekyll:250:in '<top (required)>'
    from /home/mark-work/.rvm/gems/ruby-1.9.3-p327/bin/jekyll:19:in 'load'
    from /home/mark-work/.rvm/gems/ruby-1.9.3-p327/bin/jekyll:19:in '<main>'
    from /home/mark-work/.rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in 'eval'
    from /home/mark-work/.rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in '<main>'

My colleague can reproduce the problem on Mac OSX with Ruby 1.9.3. The proposed patch fixes both cases.

@marxjohnson

I can confirm that the error is caused by files containing the pattern you describe above. I've tried running one of the files through kramdown manually (without jekyll) and the error is produced.

@gettalong
Owner

Thanks for confirming the issue! However, as explained in my first comment, the proposed fix is a fix, but not the correct one. There is a problem in the control flow of the method - will look at it later today.

@marxjohnson

I appreciate that now. Thanks for looking in to this.

@gettalong
Owner

Fixed the underlying issue and released new version 0.14.1!

@gettalong gettalong closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 27, 2012
  1. Fixed deprecated method call in list parser

    Mark Johnson authored
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  lib/kramdown/parser/kramdown/list.rb
View
2  lib/kramdown/parser/kramdown/list.rb
@@ -214,7 +214,7 @@ def parse_definition_list
else
last = nil
end
- if it.children.first.type == :p && !it.options.delete(:first_as_para)
+ if it.children.first.class == :p && !it.options.delete(:first_as_para)
it.children.first.children.first.value << "\n" if it.children.size > 1
it.children.first.options[:transparent] = true
end
Something went wrong with that request. Please try again.