diff --git a/lib/haml/filters/growstuff_markdown.rb b/lib/haml/filters/growstuff_markdown.rb index 35333a256..7069590e7 100644 --- a/lib/haml/filters/growstuff_markdown.rb +++ b/lib/haml/filters/growstuff_markdown.rb @@ -7,7 +7,7 @@ module Haml::Filters def render(text) # turn [tomato](crop) into [tomato](http://growstuff.org/crops/tomato) - expanded = text.gsub(/\[(.*?)\]\(crop\)/) do |m| + expanded = text.gsub(/\[([^\[\]]+?)\]\(crop\)/) do |m| crop_str = $1 # find crop case-insensitively crop = Crop.where('lower(name) = ?', crop_str.downcase).first diff --git a/spec/lib/haml/filters/growstuff_markdown_spec.rb b/spec/lib/haml/filters/growstuff_markdown_spec.rb index 566740307..cc6a2af54 100644 --- a/spec/lib/haml/filters/growstuff_markdown_spec.rb +++ b/spec/lib/haml/filters/growstuff_markdown_spec.rb @@ -52,4 +52,14 @@ describe 'Haml::Filters::Growstuff_Markdown' do rendered.should match /#{output_link(@crop, 'ToMaTo')}/ end + + it "doesn't convert when it's not followed by '(crop)'" do + tomato = FactoryGirl.create(:tomato) + maize = FactoryGirl.create(:maize) + string = "[maize](http://example.com) #{input_link(tomato)}" + rendered = Haml::Filters::GrowstuffMarkdown.render(string) + rendered.should match /#{output_link(tomato)}/ + rendered.should_not match /#{output_link(maize)}/ + rendered.should match "maize" + end end