-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
allow non-string template source #1775
Conversation
lib/liquid/template.rb
Outdated
@@ -108,7 +108,7 @@ def initialize | |||
def parse(source, options = {}) | |||
parse_context = configure_options(options) | |||
|
|||
unless source.valid_encoding? | |||
if source.is_a?(String) && !source.valid_encoding? |
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.
What if the to_s
value is a string with an invalid encoding?
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 catch... That is possible...
class ByteString
def to_s
"\xC0"
end
end
Liquid::Template.parse(ByteString.new) # this should raise an error
I have updated the PR to convert the source
to a String
object from the Template#parse
function instead of Tokenize#initialize
.
Wait what? How/when does this happen? |
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.
Code lgtm but man... why 😞
What are you trying to solve?
#1774 introduced a bug that doesn't allow non-string values such as
nil
orInteger
as a template source.Expected behaviour:
How are you solving this?
This PR updates the
Template#parse
to only check the template's validity if the template is aString