From d425a70fad08d14b4fe243e866ee05481bd5b839 Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Fri, 27 Mar 2009 09:25:08 -0500 Subject: [PATCH] Yikes! Yet more dangerously greedy Regexps in Maruku, and one of my own. --- lib/chunks/literal.rb | 2 +- vendor/plugins/maruku/lib/maruku/input/html_helper.rb | 4 ++-- vendor/plugins/maruku/lib/maruku/input/parse_block.rb | 4 ++-- vendor/plugins/maruku/lib/maruku/input/parse_span_better.rb | 4 ++-- vendor/plugins/maruku/lib/maruku/input/type_detection.rb | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/chunks/literal.rb b/lib/chunks/literal.rb index a345a041..35adabcd 100644 --- a/lib/chunks/literal.rb +++ b/lib/chunks/literal.rb @@ -32,7 +32,7 @@ module Literal class Math < AbstractLiteral MATH_START = '(\${1,2}|' + Regexp.escape('\[') + '|\\begin\{equation\})' MATH_END = '(\${1,2}|' + Regexp.escape('\]') + '|\\end\{equation\})' - MATH_PATTERN = Regexp.new(MATH_START + '([^$]|\\\$)+' + MATH_END, Regexp::MULTILINE) + MATH_PATTERN = Regexp.new(MATH_START + '([^$]|\\\$)+?' + MATH_END, Regexp::MULTILINE) def self.pattern() MATH_PATTERN end end diff --git a/vendor/plugins/maruku/lib/maruku/input/html_helper.rb b/vendor/plugins/maruku/lib/maruku/input/html_helper.rb index c2f5a8e0..e6c43d5e 100644 --- a/vendor/plugins/maruku/lib/maruku/input/html_helper.rb +++ b/vendor/plugins/maruku/lib/maruku/input/html_helper.rb @@ -28,12 +28,12 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser class HTMLHelper include MaRuKu::Strings - Tag = %r{^<(/)?(\w+)\s*([^>]*)>}m + Tag = %r{^<(/)?(\w+)\s*([^>]*?)>}m PartialTag = %r{^<.*}m EverythingElse = %r{^[^<]+}m CommentStart = %r{^} + CommentEnd = %r{^.*?-->} TO_SANITIZE = ['img','hr','br'] attr_reader :rest diff --git a/vendor/plugins/maruku/lib/maruku/input/parse_block.rb b/vendor/plugins/maruku/lib/maruku/input/parse_block.rb index 0cec4a89..e29c8488 100644 --- a/vendor/plugins/maruku/lib/maruku/input/parse_block.rb +++ b/vendor/plugins/maruku/lib/maruku/input/parse_block.rb @@ -177,7 +177,7 @@ module MaRuKu; module In; module Markdown; module BlockLevelParser line = src.shift_line.strip al = nil # Check if there is an IAL - if new_meta_data? and line =~ /^(.*)\{(.*)\}\s*$/ + if new_meta_data? and line =~ /^(.*?)\{(.*?)\}\s*$/ line = $1.strip ial = $2 al = read_attribute_list(CharSource.new(ial,src), context=nil, break_on=[nil]) @@ -193,7 +193,7 @@ module MaRuKu; module In; module Markdown; module BlockLevelParser line = src.shift_line.strip al = nil # Check if there is an IAL - if new_meta_data? and line =~ /^(.*)\{(.*)\}\s*$/ + if new_meta_data? and line =~ /^(.*?)\{(.*?)\}\s*$/ line = $1.strip ial = $2 al = read_attribute_list(CharSource.new(ial,src), context=nil, break_on=[nil]) diff --git a/vendor/plugins/maruku/lib/maruku/input/parse_span_better.rb b/vendor/plugins/maruku/lib/maruku/input/parse_span_better.rb index 6aad7889..1bab9c50 100644 --- a/vendor/plugins/maruku/lib/maruku/input/parse_span_better.rb +++ b/vendor/plugins/maruku/lib/maruku/input/parse_span_better.rb @@ -299,7 +299,7 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser end def extension_meta(src, con, break_on_chars) - if m = src.read_regexp(/([^\s\:\"\']+):/) + if m = src.read_regexp(/([^\s\:\"\']+?):/) name = m[1] al = read_attribute_list(src, con, break_on_chars) # puts "#{name}=#{al.inspect}" @@ -443,7 +443,7 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser # R_REF_ID = Regexp.compile(/([^\]\s]*)(\s*\])/) # R_REF_ID = Regexp.compile(/([^\]\s]*)(\s*\])/) - R_REF_ID = Regexp.compile(/([^\]]*)\]/) + R_REF_ID = Regexp.compile(/([^\]]*?)\]/) # Reads a bracketed id "[refid]". Consumes also both brackets. def read_ref_id(src, con) diff --git a/vendor/plugins/maruku/lib/maruku/input/type_detection.rb b/vendor/plugins/maruku/lib/maruku/input/type_detection.rb index cd91d6ef..716fde70 100644 --- a/vendor/plugins/maruku/lib/maruku/input/type_detection.rb +++ b/vendor/plugins/maruku/lib/maruku/input/type_detection.rb @@ -143,5 +143,5 @@ module MaRuKu; module Strings TableSeparator = %r{^(\|?#{Sep}\|?)+?\s*$} - EMailAddress = /<([^:]+@[^:]+)>/ + EMailAddress = /<([^:]+?@[^:]+?)>/ end end