gjtorikian / html-pipeline

HTML processing filters and utilities
MIT License
2.27k stars 383 forks source link

Bug in specification of node filters in v3.0.0 #388

Closed stevehill1981 closed 11 months ago

stevehill1981 commented 11 months ago

If you configure a HTMLPipeline with an odd number of node_filters, you get an ArgumentError:

 ArgumentError:
   odd number of arguments for Hash

Using an even number of node_filters allows it to work as expected. I'd guess that the array is being turned into a Hash somewhere, which does make me wonder if the node filters are being correctly called (but I haven't proven this yet).

This works:

input = "Hey there!"

HTMLPipeline.new(
  convert_filter: HTMLPipeline::ConvertFilter::MarkdownFilter.new,
  node_filters: [
    HTMLPipeline::NodeFilter::SyntaxHighlightFilter.new,
    HTMLPipeline::NodeFilter::TableOfContentsFilter.new,
    HTMLPipeline::NodeFilter::EmojiFilter.new,
    HTMLPipeline::NodeFilter::HttpsFilter.new,
  ]
).call(input)

This does not:

input = "Hey there!"

HTMLPipeline.new(
  convert_filter: HTMLPipeline::ConvertFilter::MarkdownFilter.new,
  node_filters: [
    HTMLPipeline::NodeFilter::SyntaxHighlightFilter.new,
    HTMLPipeline::NodeFilter::TableOfContentsFilter.new,
    HTMLPipeline::NodeFilter::EmojiFilter.new,
  ]
).call(input)

I'll have a further dig and PR if I can find the issue, but maybe someone else already knows!

stevehill1981 commented 11 months ago

Looks like this is being triggered here: https://github.com/gjtorikian/html-pipeline/blob/6c9d27efa0f9a73c5918bc26f96c5afcf179a760/lib/html_pipeline.rb#L181

It doesn't fail until we have more than 2 node filters defined; when I stripped back to just 1, it worked correctly. As soon as I added the third, it failed. When I added the fourth, it worked!

I suspect it's going to fail with 5, work with 6 and so on...