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

Making Drop output pretty #808

Closed
parkr opened this issue Oct 11, 2016 · 6 comments
Closed

Making Drop output pretty #808

parkr opened this issue Oct 11, 2016 · 6 comments

Comments

@parkr
Copy link
Contributor

parkr commented Oct 11, 2016

Hey! Spelunking through the Jekyll, Liquid, and Ruby source code, I noticed an oddity with output.join when it contains a Drop.

In Block#render_all, you create an output variable, which is an empty array, []. As you iterate through the various nodes in the @nodelist, you append their token_output to output using output << token_output. Then, at the end, you return the value of output.join, which calls checks if it's a string via rb_check_string_type and if not joins it using rb_ary_join_0.

If token_output is a Liquid::Drop, then output.join causes the output of [#<Liquid::Drop ...>] to be Liquid::Drop. For some reason, it just gets the output of value.class.name. I can't seem to change this for a Drop I'm writing.

@parkr
Copy link
Contributor Author

parkr commented Oct 11, 2016

/cc @fw42 @dylanahsmith @pushrax

@fw42
Copy link
Contributor

fw42 commented Oct 11, 2016

if I remember correctly, this is on purpose and was a "security" fix (as in possible information leakage)

@fw42
Copy link
Contributor

fw42 commented Oct 11, 2016

#306

@parkr
Copy link
Contributor Author

parkr commented Oct 11, 2016

@fw42 Thank you! I saw to_s, tried to override it, but for some reason it didn't work. Maybe it conflicts with #to_str, which is what I see in the Ruby source code?

@pushrax
Copy link
Contributor

pushrax commented Oct 13, 2016

to_str is actually what you want here – it's the duck-typed version of a "string trait" (if Ruby had traits).

@parkr
Copy link
Contributor Author

parkr commented Oct 17, 2016

Thanks! Not sure if this is something that should be documented. "To print a Drop, ensure #to_str is defined."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants