-
Notifications
You must be signed in to change notification settings - Fork 347
Asciidoctor: Be careful about bad callouts #602
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
Asciidoctor: Be careful about bad callouts #602
Conversation
Stops the callout image copying code from attempting to copy the images for bad callouts and crashing.
block.parent.context == :colist | ||
id = block.attr('coids').scan(/CO(?:\d+)-(\d+)/) { | ||
block.parent.context == :colist && | ||
(coids = block.attr 'coids') |
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.
As I review more of this, my ability to read/remember ruby grows, but there are still some big holes.
So, correct me if I am wrong but, I think this code (as well as line 30 there) is:
- abusing
.attr
as an accessor to an instance variable (presumably to get around name requirements) - abusing that ruby allows assigning a value during a predicate check
- discarding the assigned symbol for the value, and
- boolean punning as an existence check over returning the assignment value as a side-effect
If I am right about any (or, yikes, all) of that, then yeah I feel I wouldn't be a good reviewer if I did not protest, because that's a whole lot of scary things.
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.
1. abusing `.attr` as an accessor to an instance variable (presumably to get around name requirements)
attr
is a method on AbstractNode. I believe you are thinking of instance_variable_get
. Or of attr_reader
/attr_writer
/attr
syntax used to make instance members publicly accessible.
abusing that ruby allows assigning a value during a predicate check
It does indeed do that. I stayed away from it for a long time but the more of asciidoctor's code that I read the more this sort of behavior rubs off on me.
discarding the assigned symbol for the value, and
I use the result of the assignment on the next line I think.
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.
I use the result of the assignment on the next line I think.
Woops. I don't. I should be.
boolean punning as an existence check over returning the assignment value as a side-effect
It uses the "the result of an assignment is the value that was assigned" behavior and the ruby's default truthiness rules. I certainly didn't intend to throw out the result of the assignment.
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.
I've pushed a change that uses the attribute that I read.
I can certainly move the assignment if you'd like. I would have done it a few weeks ago but this is more in line with the way asciidoctor is written.
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.
@ddillinger, have a look at #604 - there I rewrote this if statement to be less "magical ruby".
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.
It solves a different problem but sets the style that I'd use to solve this one if you prefer that.
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.
That PR is more readable for sure!
@ddillinger I've pushed an update to this uses the less "magical ruby" style. |
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.
Stops the callout image copying code from attempting to copy the images for bad callouts and crashing.
Stops the callout image copying code from attempting to copy the images
for bad callouts and crashing.