asciidoctor.js icon indicating copy to clipboard operation
asciidoctor.js copied to clipboard

Block#getContent() can return Opal.nil

Open mojavelinux opened this issue 2 years ago • 4 comments

For certain blocks, calling getContent() can return Opal.nil. Until Asciidoctor > 2.0.18 is released, this can happen if a raw (e.g., passthrough) or verbatim (e.g., listing) block has no lines.

console.dir(Asciidoctor.load('----\n----').getBlocks()[0].getContent())

The Opal.nil return value can also happen if this method is called on a block macro. Regardless of this variation in core, I think Asciidoctor.js should protect against client code setting an Opal.nil return value.

mojavelinux avatar Apr 09 '23 07:04 mojavelinux

I believe that's already the case in Asciidoctor.js 3.0.

Asciidoctor > 2.0.18 is released

It will actually change the behavior, in Asciidoctor.js 3.0 we return undefined but when building against Asciidoctor > 2.0.18 we return ''. Should Iwe return undefined or ''?

ggrossetie avatar Apr 10 '23 13:04 ggrossetie

I think we should return undefined. I'm going to update core to return empty string when that's what it should be, but there are times when it should be undefined (block macro).

mojavelinux avatar Apr 10 '23 21:04 mojavelinux

but there are times when it should be undefined (block macro).

Could you please provide a simple reproduction case where it returns Opal.nil?

ggrossetie avatar Apr 10 '23 22:04 ggrossetie

The original description provides an example case when it currently returns Opal.nil (but should return undefined).

Here's another case:

console.dir(Asciidoctor.load('image::test.png[]').getBlocks()[0].getContent())

We know now that this is only happening in the 2.2.x line. The 3.0.x line seems to be doing the right thing.

mojavelinux avatar Apr 10 '23 23:04 mojavelinux