-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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
Escaped regular expressions when using post_url. #5605
Conversation
Previously, the post_url function would give error messages when the post being listed contained special characters for use in regular expressions. These special characters are now escaped using Regexp.escape.
/cc @jekyll/stability |
Hello! Thanks so much for the pull request. In order to evaluate this change and to prevent it from regressing in the future, we would like to see a unit test added to |
@@ -14,7 +14,8 @@ def initialize(name) | |||
"'#{name}' does not contain valid date and/or title." | |||
end | |||
|
|||
@name_regex = %r!^_posts/#{path}#{date}-#{slug}\.[^.]+| | |||
escaped_slug = Regexp.escape(slug) | |||
@name_regex = %r!^_posts/#{path}#{date}-#{escaped_slug}\.[^.]+| | |||
^#{path}_posts/?#{date}-#{slug}\.[^.]+!x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the latter slug
be escaped too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. I had missed that one, and the updated pull request has both slug
s escaped.
There is now a unit test in |
@Lunderberg please update this test as well to have our CI go green.. Thanks! 😃 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more thing then we're done! 😄
refute_match(%r!markdown\-html\-error!, @result) | ||
end | ||
|
||
should "have the URL to the \"complex\" post from 2008-11-21" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test name should be updated 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can single quotes be used here, (for cleanliness)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good points, both changes have been made.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😄 I was actually asking Parker if that was allowed, but since you @Lunderberg implemented it anyways, can we switch the quotes to have it "have the URL to the 'special-chars' post from 2016-11-26"
for homogeneity with other unit-tests..? also, there's more instances of Thanks\""
inside test names within the same test-file.. can you patch that as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cleaning other unit-test-names is perhaps beyond the scope of this pull.. so we'll tackle those in another PR..
Wonderful work, thank you! @jekyllbot: merge +bug |
Previously, the post_url function would give error messages when the post being listed contained special characters for use in regular expressions. These special characters are now escaped using
Regexp.escape
.This is in reference to issue #3486.