jbowens / jBBCode

A lightweight but extensible BBCode parser
http://jbbcode.com
MIT License
164 stars 32 forks source link

Wrong evaluation with bracket inside a tag #21

Closed Art4 closed 10 years ago

Art4 commented 10 years ago

Hi,

I've found a bug while parsing a [ bracket inside a tag e.g. [b]:-[ [/b]. I've written 3 tests to specify the error. You can find them in this commit.

    public function testBracketInTag()
    {
        $this->assertProduces('[b]:-[[/b]', '<strong>:-[</strong>');
    }

    public function testBracketWithSpaceInTag()
    {
        $this->assertProduces('[b]:-[ [/b]', '<strong>:-[ </strong>');
    }

    public function testBracketWithTextInTag()
    {
        $this->assertProduces('[b]:-[ foobar[/b]', '<strong>:-[ foobar</strong>');
    }

As you can see the test testBracketInTag() works fine. The other tests testBracketWithSpaceInTag() and testBracketWithTextInTag() fails with something like <strong>:-[ /b]</strong>.

Here is the result of running the tests:

$ phpunit .
PHPUnit 4.0.17 by Sebastian Bergmann.

..........................................FF.................

Time: 208 ms, Memory: 2.75Mb

There were 2 failures:

1) SimpleEvaluationTest::testBracketWithSpaceInTag
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'<strong>:-[ </strong>'
+'<strong>:-[ /b]</strong>'

[...]jBBCode/JBBCode/tests/SimpleEvaluationTest.php:28
[...]jBBCode/JBBCode/tests/SimpleEvaluationTest.php:99

2) SimpleEvaluationTest::testBracketWithTextInTag
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'<strong>:-[ foobar</strong>'
+'<strong>:-[ foobar/b]</strong>'

[...]jBBCode/JBBCode/tests/SimpleEvaluationTest.php:28
[...]jBBCode/JBBCode/tests/SimpleEvaluationTest.php:104

FAILURES!
Tests: 61, Assertions: 99, Failures: 2.

I haven't take a look in the code so far. Is there a chance for a quick bugfix?