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

Escaped regular expressions when using post_url. #5605

Merged
merged 4 commits into from
Nov 28, 2016

Conversation

Lunderberg
Copy link
Contributor

@Lunderberg Lunderberg commented Nov 26, 2016

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.

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.
@ghost
Copy link

ghost commented Nov 26, 2016

/cc @jekyll/stability

@jekyllbot jekyllbot assigned ghost Nov 26, 2016
@parkr
Copy link
Member

parkr commented Nov 26, 2016

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 test/test_tags.rb. You should see examples for this tag in that file. Let us know if we can help!

@@ -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
Copy link

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?

Copy link
Contributor Author

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 slugs escaped.

@Lunderberg
Copy link
Contributor Author

There is now a unit test in test/test_tags.rb to test the escaping of special characters. The test succeeds with the change applied, and fails when the change is not present. I haven't used ruby very much before, so it is mainly a copy-paste-modify of an existing test, with small modifications.

@ashmaroli
Copy link
Member

@Lunderberg please update this test as well to have our CI go green.. Thanks! 😃

Copy link
Member

@parkr parkr left a 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
Copy link
Member

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 😄

Copy link
Member

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)?

Copy link
Contributor Author

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.

Copy link
Member

@ashmaroli ashmaroli Nov 28, 2016

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 \"" inside test names within the same test-file.. can you patch that as well? Thanks

Copy link
Member

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..

@parkr
Copy link
Member

parkr commented Nov 28, 2016

Wonderful work, thank you!

@jekyllbot: merge +bug

@jekyllbot jekyllbot merged commit c3bf59c into jekyll:master Nov 28, 2016
jekyllbot added a commit that referenced this pull request Nov 28, 2016
@jekyll jekyll locked and limited conversation to collaborators Jan 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants