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

fix date parsing in file names to be stricter #5609

Merged
merged 4 commits into from Nov 29, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion lib/jekyll/document.rb
Expand Up @@ -9,7 +9,7 @@ class Document

YAML_FRONT_MATTER_REGEXP = %r!\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)!m
DATELESS_FILENAME_MATCHER = %r!^(?:.+/)*(.*)(\.[^.]+)$!
DATE_FILENAME_MATCHER = %r!^(?:.+/)*(\d+-\d+-\d+)-(.*)(\.[^.]+)$!
DATE_FILENAME_MATCHER = %r!^(?:.+/)*(\d{4}-\d{2}-\d{2})-(.*)(\.[^.]+)$!

# Create a new Document.
#
Expand Down
5 changes: 5 additions & 0 deletions test/source/_methods/3940394-21-9393050-fifif1323-test.md
@@ -0,0 +1,5 @@
---
title: "this is a test!"
---

wheee
29 changes: 29 additions & 0 deletions test/test_document.rb
Expand Up @@ -492,4 +492,33 @@ def assert_equal_value(key, one, other)
assert_equal true, File.file?(@dest_file)
end
end

context "a document in a collection with dash-separated numeric file name" do
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't really need these tests because most others in this spec file will fail if the regex is wrong, but i added them for consistency

setup do
@site = fixture_site({
"collections" => {
"methods" => {
"output" => true
}
}
})
@site.process
@document = @site.collections["methods"].docs.find do |doc|
doc.relative_path == "_methods/3940394-21-9393050-fifif1323-test.md"
end
@dest_file = dest_dir("methods/3940394-21-9393050-fifif1323-test.html")
end

should "produce the right URL" do
assert_equal "/methods/3940394-21-9393050-fifif1323-test.html", @document.url
end

should "produce the right destination" do
assert_equal @dest_file, @document.destination(dest_dir)
end

should "be output in the correct place" do
assert_equal true, File.file?(@dest_file)
end
end
end