-
-
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
URL: warn if key doesn't exist in url drop #5524
Conversation
/cc @jekyll/core |
replacement = @placeholders.public_send(match.sub(":".freeze, "".freeze)) | ||
begin | ||
replacement = @placeholders.public_send(match.sub(":".freeze, "".freeze)) | ||
rescue NoMethodError |
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.
Instead of a begin .. rescue
, what about checking for the key first, like
template.gsub(%r!:([a-z_]+)!) do |match|
key = match.sub(":".freeze, "".freeze)
raise NoMethodError, "No URL template key #{key} exists!" unless @placeholders.key?(key)
if @placeholders[key].nil?
"".freeze
else
self.class.escape_path(@placeholders[key])
end
end.gsub(%r!//!, "/".freeze)
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.
hmm, that makes more sense, yeah
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.
hmm, by using this approach, it looks like the URLDrop (at least the one i use in my tests) throws an unrelated error because it can't find fallback_data
when using key?
or #[]
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.
Ah, ok. No problem. Define def fallback_data
in UrlDrop
as an empty hash.
class UrlDrop
private
def fallback_data
{}
end
end
updated according to @parkr's comments |
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.
LGTM!
@jekyll/core is this ok to merge? its been sitting for a while |
@jekyllbot: merge +minor |
fixes #5332
the tests only cover not throwing a
NoMethodError
because i can't figure out how to capture the logged message to check if it logged the correct message (minitest'scapture_io
only works with kernelputs
, weirdly enough)