From ef2d558874d5fe24db751fec2a07a52166482360 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 17 Jan 2015 16:25:10 -0800 Subject: [PATCH 1/3] Markdown#matches should avoid regexp --- lib/jekyll/converters/markdown.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/jekyll/converters/markdown.rb b/lib/jekyll/converters/markdown.rb index f0d1afb0..39389874 100644 --- a/lib/jekyll/converters/markdown.rb +++ b/lib/jekyll/converters/markdown.rb @@ -46,15 +46,12 @@ module Jekyll ].map(&:to_sym) end - def extname_matches_regexp - @extname_matches_regexp ||= Regexp.new( - '^\.(' + @config['markdown_ext'].gsub(',','|') +')$', - Regexp::IGNORECASE - ) + def extname_list + @extname_list ||= @config['markdown_ext'].split(',').map { |e| ".#{e.downcase}" } end def matches(ext) - ext =~ extname_matches_regexp + extname_list.include? ext.downcase end def output_ext(ext) From aaf0ba15ccbf9e2ded565b4115af9dd22b24ff8a Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 17 Jan 2015 16:25:33 -0800 Subject: [PATCH 2/3] Use frozen regular expressions for Utils#slugify --- lib/jekyll/utils.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/jekyll/utils.rb b/lib/jekyll/utils.rb index ba0303a4..bba8b148 100644 --- a/lib/jekyll/utils.rb +++ b/lib/jekyll/utils.rb @@ -2,6 +2,12 @@ module Jekyll module Utils extend self + # Constants for use in #slugify + SLUGIFY_MODES = %w{raw default pretty} + SLUGIFY_RAW_REGEXP = Regexp.new('\\s+').freeze + SLUGIFY_DEFAULT_REGEXP = Regexp.new('[^[:alnum:]]+').freeze + SLUGIFY_PRETTY_REGEXP = Regexp.new("[^[:alnum:]._~!$&'()+,;=@]+").freeze + # Merges a master hash with another hash, recursively. # # master_hash - the "parent" hash whose values will be overridden @@ -129,19 +135,18 @@ module Jekyll def slugify(string, mode=nil) mode ||= 'default' return nil if string.nil? + return string.downcase unless SLUGIFY_MODES.include?(mode) # Replace each character sequence with a hyphen re = case mode when 'raw' - Regexp.new('\\s+') + SLUGIFY_RAW_REGEXP when 'default' - Regexp.new('[^[:alnum:]]+') + SLUGIFY_DEFAULT_REGEXP when 'pretty' # "._~!$&'()+,;=@" is human readable (not URI-escaped) in URL # and is allowed in both extN and NTFS. - Regexp.new("[^a-zA-Z0-9._~!$&'()+,;=@]+") - else - return string.downcase + SLUGIFY_PRETTY_REGEXP end string. From f11837dd7b203f622b3b79b5c929b779acbf317a Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 17 Jan 2015 16:48:12 -0800 Subject: [PATCH 3/3] Fix cucumber failures due to merge of #3134. --- features/collections.feature | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/collections.feature b/features/collections.feature index 1cdbff4b..91a271fc 100644 --- a/features/collections.feature +++ b/features/collections.feature @@ -118,7 +118,7 @@ Feature: Collections """ When I run jekyll build Then the _site directory should exist - And I should see "Item count: 1" in "_site/index.html" + And I should see "Item count: 2" in "_site/index.html" Scenario: Sort by title Given I have an "index.html" page that contains "{% assign items = site.methods | sort: 'title' %}1. of {{ items.size }}: {{ items.first.output }}" @@ -130,7 +130,7 @@ Feature: Collections """ When I run jekyll build Then the _site directory should exist - And I should see "1. of 6:

Page without title.

" in "_site/index.html" + And I should see "1. of 7:

Page without title.

" in "_site/index.html" Scenario: Sort by relative_path Given I have an "index.html" page that contains "Collections: {% assign methods = site.methods | sort: 'relative_path' %}{% for method in methods %}{{ method.title }}, {% endfor %}"