Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a quick test for DataReader #6284

Merged
merged 2 commits into from Aug 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/jekyll/readers/data_reader.rb
Expand Up @@ -70,8 +70,8 @@ def read_data_file(path)
end

def sanitize_filename(name)
name.gsub!(%r![^\w\s-]+|(?<=^|\b\s)\s+(?=$|\s?\b)!, "".freeze)
name.gsub(%r!\s+!, "_")
name.gsub(%r![^\w\s-]+|(?<=^|\b\s)\s+(?=$|\s?\b)!, "")
.gsub(%r!\s+!, "_")
end
end
end
17 changes: 17 additions & 0 deletions test/test_data_reader.rb
@@ -0,0 +1,17 @@
# frozen_string_literal: true

require "helper"

class TestDataReader < JekyllUnitTest
context "#sanitize_filename" do
setup do
@reader = DataReader.new(fixture_site)
end

should "remove evil characters" do
assert_equal "helpwhathaveIdone", @reader.sanitize_filename(
"help/what^&$^#*(!^%*!#haveId&&&&&&&&&one"
)
end
end
end