Skip to content

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

Merged
merged 3 commits into from
Feb 14, 2019

Conversation

nik9000
Copy link
Member

@nik9000 nik9000 commented Feb 12, 2019

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.
@nik9000 nik9000 requested a review from ddillinger February 12, 2019 18:44
block.parent.context == :colist
id = block.attr('coids').scan(/CO(?:\d+)-(\d+)/) {
block.parent.context == :colist &&
(coids = block.attr 'coids')
Copy link

@ddillinger ddillinger Feb 12, 2019

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:

  1. abusing .attr as an accessor to an instance variable (presumably to get around name requirements)
  2. abusing that ruby allows assigning a value during a predicate check
  3. discarding the assigned symbol for the value, and
  4. 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.

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member Author

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".

Copy link
Member Author

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.

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!

@nik9000
Copy link
Member Author

nik9000 commented Feb 13, 2019

@ddillinger I've pushed an update to this uses the less "magical ruby" style.

Copy link

@ddillinger ddillinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more magic

@nik9000 nik9000 merged commit 385d1b9 into elastic:master Feb 14, 2019
nik9000 added a commit that referenced this pull request Feb 15, 2019
Stops the callout image copying code from attempting to copy the images
for bad callouts and crashing.
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

Successfully merging this pull request may close these issues.

2 participants