thunderer / Shortcode

Advanced shortcode (BBCode) parser and engine for PHP
http://kowalczyk.cc
MIT License
378 stars 29 forks source link

Parse error with Vietnamese characters or open and close tag only #79

Closed xuannghia closed 5 years ago

xuannghia commented 5 years ago

Hello, Thank you because this library. But I have some issues with some content below:

  1. Issue with Vietnamese characters:
    [container]
    [Tiêu đề]
    [/container]

    In this case I want to show <div class="container">[Tiêu đề]</div> ("Tiêu đề" is "Title" in English) but the container shortcode auto close and I get <div class="container"></div>[Tiêu đề][/container]

But this content will working if it is not contain Vietnamese characters:

[container]
[Tieu de]
[/container]
  1. Issue with open and close tag only
    [container]
    []
    [/container]

    In this case I want to show <div class="container">[]</div> but the container shortcode auto close and I get <div class="container"></div>[][/container]. Similar to issue one.

Can you help me fix these issues?

Thank you.

thunderer commented 5 years ago

Hi @xuannghia, can you post the code to reproduce the issues reported above?

xuannghia commented 5 years ago

Hi @thunderer This is my example code

<?php
require_once 'vendor/autoload.php';

use Thunder\Shortcode\HandlerContainer\HandlerContainer;
use Thunder\Shortcode\Parser\RegularParser;
use Thunder\Shortcode\Processor\Processor;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
use Thunder\Shortcode\Syntax\Syntax;

function shortcode($text) {
    $handlers = new HandlerContainer();
    $handlers->add('container', function(ShortcodeInterface $s) {
        return '<div class="container">'.$s->getContent().'</div>';
    });
    $defaultSyntax = new Syntax('[', ']', '/', '=', '"');
    $processor = new Processor(new RegularParser($defaultSyntax), $handlers);
    return $processor->process($text);
}

$case_1 = '[container][Tiêu đề][/container]';
$case_2 = '[container][][/container]';

echo shortcode($case_1); // I get <div class="container"></div>[Tiêu đề][/container]
echo shortcode($case_2); // I get <div class="container"></div>[][/container]

P/s: I use PHP 7.3 and thunderer/shortcode version 0.6.5 (I install with composer)

Thank you.

xuannghia commented 5 years ago

Oh, sorry for my mistake. These issues have been resolved in version 0.7.2. But file README.md instructing me for installing version 0.6.5. Can you change it so that those who come later do not have to meet the situation like me?

thunderer commented 5 years ago

@xuannghia are both issues resolved by upgrading to v0.7? I will update the README shortly.

thunderer commented 5 years ago

@xuannghia can you confirm that the upgrade you mentioned above resolved both problems? If so, can we close this issue?

xuannghia commented 5 years ago

@thunderer Yes, upgrading to v0.7.2 can fix both issues. Sorry for the late reply.