#183 ✓ resolved
Tommy Li

Three newlines after a list at end of file make dangling <li>

Reported by Tommy Li | February 6th, 2010 @ 03:54 AM

Three newlines after a list at end of file make dangling <li>

I'm going to escape newlines to illustrate the problem.

Consider this textile:

* a\n
* b\n
* c\n
\n
\n

This will yield:

<ul>
    <li>a</li>
    <li>b</li>
    <li>c</li>
</ul>
<li>

This is incorrect.

Comments and changes to this ticket

  • Jason Garber

    Jason Garber March 1st, 2010 @ 08:53 AM

    • State changed from “new” to “open”

    Confirmed bug. Here's the test case


    ---
    name: three newlines after a list
    in: "* a\n* b\n* c\n\n\n"
    html: |-
      <ul>
        <li>a</li>
        <li>b</li>
        <li>c</li>
      </ul>
    
  • Jason Garber

    Jason Garber March 1st, 2010 @ 08:53 AM

    • Tag set to lists
  • Stephen Bannasch

    Stephen Bannasch January 14th, 2011 @ 02:19 AM

    • Milestone order changed from “0” to “0”

    A colleague generated a pull request with a new rspec test that exposes this bug:

    https://github.com/jgarber/redcloth/pull/1

    I checked and the bug is present on master.

    I just took a look at the ragel code but it's been quite a while since I've used ragel and it's not quite as easy to parse as Ruby ;-)

    Seems like li_open in lib/redcloth/formatters/html.rb is being called incorrectly when the thrid newline is parsed.

    Here are the locations in the code where li_open is referenced:

    $ ack --all-types li_open
    
      ext/redcloth_scan/redcloth.h
      202:    ASET("type", "li_open");
    
      ext/redcloth_scan/RedclothScanService.java
      95:     ASET("type", "li_open");
    
      lib/redcloth/formatters/html.rb
      50:  def li_open(opts)
    
      lib/redcloth/formatters/latex.rb
      103:  def li_open(opts)
    
      ragel/redcloth_scan.java.rl
      94:     ASET("type", "li_open");
    
      ragel/redcloth_scan.rb.rl
      309:      ASET("type", "li_open")
    

    Here's the new spec test:

    it "should not add spurious li tags to the end of markup" do
      input         = "* one\n* two\n* three \n\n"
      failing_input = "* one\n* two\n* three \n\n\n"
      RedCloth.new(input).to_html.should_not match /<li>$/
      RedCloth.new(failing_input).to_html.should_not match /<li>$/
    end
    

    When I run the spec test in the debugger:

    $ rspec -d spec/parser_spec.rb
    

    RedCloth::Formatters::HTML.li_open(opts) is called once for each of the three list items in the first test:

    RedCloth.new(input).to_html.should_not match /<li>$/
    

    and then called again once for each list item in the second test:

    RedCloth.new(failing_input).to_html.should_not match /<li>$/
    

    and then it is called a seventh time with this argument: {:type=>"li_open", :nest=>0, :text=>""}

       50    def li_open(opts)
       51      debugger
    => 52      "#{"\t" * opts[:nest]}<li#{pba(opts)}>#{opts[:text]}"
       53    end
    

    values of argument opts:

    1: {:type=>"li_open", :nest=>1, :text=>"one"}
    2: {:type=>"li_open", :nest=>1, :text=>"two"}
    3: {:type=>"li_open", :nest=>1, :text=>"three"}
    4: {:type=>"li_open", :nest=>1, :text=>"one"}
    5: {:type=>"li_open", :nest=>1, :text=>"two"}
    6: {:type=>"li_open", :nest=>1, :text=>"three"}
    7: {:type=>"li_open", :nest=>0, :text=>""}
    

    The nesting level is 0 and the text is an empty string ...

    Is there a way to tell more about what the ragel machine has been doing and why li_open was called this last time?

  • Stephen Bannasch
  • Jason Garber

    Jason Garber January 23rd, 2011 @ 07:30 PM

    • State changed from “open” to “resolved”

    Accepted! Thanks!

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

RedCloth is a Ruby library for converting Textile into HTML

Shared Ticket Bins

People watching this ticket

Tags

Pages