From b5cec7d33569772b68d6148eb97894ac4b14ec81 Mon Sep 17 00:00:00 2001 From: Derek Gottlieb Date: Sat, 28 May 2016 13:51:13 -0500 Subject: [PATCH 1/3] lib/jekyll/theme.rb passing rubocop --- .rubocop.yml | 1 - lib/jekyll/theme.rb | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 84c8d1b7..2665a743 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -16,7 +16,6 @@ AllCops: - lib/jekyll/renderer.rb - lib/jekyll/site.rb - lib/jekyll/static_file.rb - - lib/jekyll/theme.rb - lib/jekyll/url.rb - lib/jekyll/utils.rb - lib/jekyll.rb diff --git a/lib/jekyll/theme.rb b/lib/jekyll/theme.rb index ed9cc68d..90536de7 100644 --- a/lib/jekyll/theme.rb +++ b/lib/jekyll/theme.rb @@ -27,7 +27,7 @@ module Jekyll def configure_sass return unless sass_path - require 'sass' + require "sass" Sass.load_paths << sass_path end @@ -38,7 +38,7 @@ module Jekyll return unless resolved_dir path = Jekyll.sanitized_path(root, resolved_dir) - path if Dir.exists?(path) + path if Dir.exist?(path) end def realpath_for(folder) @@ -50,7 +50,8 @@ module Jekyll def gemspec @gemspec ||= Gem::Specification.find_by_name(name) rescue Gem::LoadError - raise Jekyll::Errors::MissingDependencyException, "The #{name} theme could not be found." + raise Jekyll::Errors::MissingDependencyException, + "The #{name} theme could not be found." end end end From 03f7bc1a8c802e095aed58efe758bbc8b71e30ec Mon Sep 17 00:00:00 2001 From: Derek Gottlieb Date: Sat, 28 May 2016 17:15:33 -0500 Subject: [PATCH 2/3] lib/jekyll/url.rb passing rubocop --- .rubocop.yml | 1 - lib/jekyll/url.rb | 24 ++++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 2665a743..8189e48e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -16,7 +16,6 @@ AllCops: - lib/jekyll/renderer.rb - lib/jekyll/site.rb - lib/jekyll/static_file.rb - - lib/jekyll/url.rb - lib/jekyll/utils.rb - lib/jekyll.rb - features/step_definitions.rb diff --git a/lib/jekyll/url.rb b/lib/jekyll/url.rb index 09975e3d..c736c0a6 100644 --- a/lib/jekyll/url.rb +++ b/lib/jekyll/url.rb @@ -1,4 +1,4 @@ -require 'uri' +require "uri" # Public: Methods that generate a URL for a resource such as a Post or a Page. # @@ -67,10 +67,10 @@ module Jekyll def generate_url_from_hash(template) @placeholders.inject(template) do |result, token| - break result if result.index(':').nil? + break result if result.index(":").nil? if token.last.nil? - # Remove leading '/' to avoid generating urls with `//` - result.gsub(/\/:#{token.first}/, '') + # Remove leading "/" to avoid generating urls with `//` + result.gsub(%r!/:#{token.first}!, "") else result.gsub(/:#{token.first}/, self.class.escape_path(token.last)) end @@ -78,21 +78,21 @@ module Jekyll end def generate_url_from_drop(template) - template.gsub(/:([a-z_]+)/.freeze) do |match| - replacement = @placeholders.public_send(match.sub(':'.freeze, ''.freeze)) + template.gsub(/:([a-z_]+)/) do |match| + replacement = @placeholders.public_send(match.sub(":".freeze, "".freeze)) if replacement.nil? - ''.freeze + "".freeze else self.class.escape_path(replacement) end - end.gsub(/\/\//.freeze, '/'.freeze) + end.gsub(%r!//!, "/".freeze) end # Returns a sanitized String URL, stripping "../../" and multiples of "/", # as well as the beginning "/" so we can enforce and ensure it. def sanitize_url(str) - "/" + str.gsub(/\/{2,}/, "/").gsub(/\.+\/|\A\/+/, "") + "/" + str.gsub(%r!/{2,}!, "/").gsub(%r!\.+\/|\A\/+!, "") end # Escapes a path to be a valid URL path segment @@ -106,7 +106,7 @@ module Jekyll # # Returns the escaped path. def self.escape_path(path) - # Because URI.escape doesn't escape '?', '[' and ']' by default, + # Because URI.escape doesn't escape "?", "[" and "]" by default, # specify unsafe string (except unreserved, sub-delims, ":", "@" and "/"). # # URI path segment is defined in RFC 3986 as follows: @@ -116,7 +116,7 @@ module Jekyll # pct-encoded = "%" HEXDIG HEXDIG # sub-delims = "!" / "$" / "&" / "'" / "(" / ")" # / "*" / "+" / "," / ";" / "=" - URI.escape(path, /[^a-zA-Z\d\-._~!$&'()*+,;=:@\/]/).encode('utf-8') + URI.escape(path, %r{[^a-zA-Z\d\-._~!$&'()*+,;=:@\/]}).encode("utf-8") end # Unescapes a URL path segment @@ -130,7 +130,7 @@ module Jekyll # # Returns the unescaped path. def self.unescape_path(path) - URI.unescape(path.encode('utf-8')) + URI.unescape(path.encode("utf-8")) end end end From db6050768d461e3d340bb1f197a8e5716bfdf55b Mon Sep 17 00:00:00 2001 From: Derek Gottlieb Date: Sat, 28 May 2016 19:23:23 -0500 Subject: [PATCH 3/3] Feedback for flubbed regex and prefer File's directory check --- lib/jekyll/theme.rb | 2 +- lib/jekyll/url.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/theme.rb b/lib/jekyll/theme.rb index 90536de7..4cd2d163 100644 --- a/lib/jekyll/theme.rb +++ b/lib/jekyll/theme.rb @@ -38,7 +38,7 @@ module Jekyll return unless resolved_dir path = Jekyll.sanitized_path(root, resolved_dir) - path if Dir.exist?(path) + path if File.directory?(path) end def realpath_for(folder) diff --git a/lib/jekyll/url.rb b/lib/jekyll/url.rb index c736c0a6..ba1abbd4 100644 --- a/lib/jekyll/url.rb +++ b/lib/jekyll/url.rb @@ -92,7 +92,7 @@ module Jekyll # as well as the beginning "/" so we can enforce and ensure it. def sanitize_url(str) - "/" + str.gsub(%r!/{2,}!, "/").gsub(%r!\.+\/|\A\/+!, "") + "/" + str.gsub(%r!/{2,}!, "/").gsub(%r!\.+/|\A/+!, "") end # Escapes a path to be a valid URL path segment