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

Optimize path sanitization of default front matter #8154

Merged
merged 1 commit into from May 10, 2020

Conversation

ashmaroli
Copy link
Member

Summary

String#gsub duplicates the given string irrespective of a pattern match.
So, it is better if one checks if a given string will match the pattern beforehand and return the original string if it doesn't match the pattern.

Regarding the pattern, %r!\A/|(?<=[^/])\z!, it translates to
Test if a given string either starts with / or just match the end-of-string preceded by a character that is not /.
The second option of the regex will always generate a match for the major use-cases
(e.g. scope["path"] == "pages" or scope["path"] == "\pages")

So we can optimize for the major use-cases by checking if the given string start_with? "/" prior to the gsub call.

@ashmaroli
Copy link
Member Author

@jekyllbot: merge +dev

@jekyllbot jekyllbot merged commit eb2423c into jekyll:master May 10, 2020
jekyllbot added a commit that referenced this pull request May 10, 2020
@ashmaroli ashmaroli deleted the optimize-fmd-sanitize-path branch May 10, 2020 15:03
@jekyll jekyll locked and limited conversation to collaborators May 10, 2021
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

3 participants