jbowens / jBBCode

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

Doesn't work with URL has quote? #78

Open dzpt opened 7 years ago

dzpt commented 7 years ago

It works with url bbcode like : [url=http://google.com]abc[/url] But failed to work with [url='http://google.com']abc[/url]

Art4 commented 7 years ago

Yes, because 'http://google.com' isn't a valid url.

You can build a custom InputValidator based on the internal one that removes the ' characters.

Then create a new url definition and add it to the parser:

$urlValidator = new \My\Own\UrlValidator();
/* [url] link tag */
$builder = new \JBBCode\CodeDefinitionBuilder('url', '<a href="{param}">{param}</a>');
$builder->setParseContent(false)->setBodyValidator($urlValidator);

// Place the CodeDefinition into the parser
$parser->addCodeDefinition($builder->build());
dzpt commented 7 years ago

I've tried your way but didn't work. Actually, it recognize 'http://google.com' as URL, then the link becomes http://domain.com/'http://google.com' , validation rules doesn't help to strip quote and return correct value? 'http://google.com' -> http://google.com

Art4 commented 7 years ago

validation rules doesn't help to strip quote and return correct value?

Sorry, you are right. You have to build a custom CodeDefinition