milesj / decoda

A lightweight lexical string parser for BBCode styled markup.
MIT License
196 stars 52 forks source link

Wrong render of tags with TAG_SELF_CLOSE type #52

Closed hilobok closed 11 years ago

hilobok commented 11 years ago
require 'vendor/autoload.php';

$decoda = new Decoda\Decoda('[div]some[hr /]text[/div]');
$decoda->defaults();
echo $decoda->parse();

outputs

<hr><div>some<hr>text</div>

Same for [br /] tag.

I think tags with TAG_SELF_CLOSE should be handled differently in Decoda::_extractNodes(), but I'm not sure to provide PR.

milesj commented 11 years ago

Try without a space [hr/], but honestly it should work. Even the test cases pass this scenario.

https://github.com/milesj/decoda/blob/master/tests/Decoda/DecodaTest.php#L508

If you can pinpoint the problem some more, it would help.

hilobok commented 11 years ago

Nope, same result without space. Problem arise when self closing tag is inside other tag.

https://github.com/milesj/decoda/blob/master/src/Decoda/Decoda.php#L1379

For self closing tags you simply add it to nodes, but I think you need to add it to parent children. Extra node appears exact after _extractNodes() call.

milesj commented 11 years ago

Interesting, will look into it more. Surprised this hasn't popped up before.