jBBCode icon indicating copy to clipboard operation
jBBCode copied to clipboard

Incorrectly displays url

Open Wertos opened this issue 7 years ago • 1 comments

[url=http://lostpix.com/?v=2018-02-04_qa1th9680k10zvlhcm8qr6zkt.png][img]http://lostpix.com/thumbs/2018-02/04/qa1th9680k10zvlhcm8qr6zkt.png[/img][/url]

<a href="http://lostpix.com/?v"><img src="http://lostpix.com/thumbs/2018-02/04/qa1th9680k10zvlhcm8qr6zkt.png" alt=""></a>

Wertos avatar Feb 04 '18 09:02 Wertos

I am unable to reproduce this issue. The BBCode works properly for me.

Input: [url=http://lostpix.com/?v=2018-02-04_qa1th9680k10zvlhcm8qr6zkt.png][img]http://lostpix.com/thumbs/2018-02/04/qa1th9680k10zvlhcm8qr6zkt.png[/img][/url]

Output: <a href="[http://lostpix.com/?v=2018-02-04_qa1th9680k10zvlhcm8qr6zkt.png](view-source:http://lostpix.com/?v=2018-02-04_qa1th9680k10zvlhcm8qr6zkt.png)"><img src="[http://lostpix.com/thumbs/2018-02/04/qa1th9680k10zvlhcm8qr6zkt.png](view-source:http://lostpix.com/thumbs/2018-02/04/qa1th9680k10zvlhcm8qr6zkt.png)"></a>

My definitions look like this: DefaultCodeDefinitionSet.php

$urlValidator = new \JBBCode\validators\UrlValidator();

// [url] link tag
$builder = new CodeDefinitionBuilder('url', '<a href="{param}">{param}</a>');
$builder->setParseContent(FALSE)->setBodyValidator($urlValidator);
array_push($this->definitions, $builder->build());

// [url=http://example.com] link tag
$builder = new CodeDefinitionBuilder('url', '<a href="{option}">{param}</a>');
$builder->setUseOption(TRUE)->setParseContent(TRUE)->setOptionValidator($urlValidator);
array_push($this->definitions, $builder->build());

UrlValidator.php

<?php

namespace JBBCode\validators;

require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'InputValidator.php';

/**
 * An InputValidator for urls. This can be used to make [url] bbcodes secure.
 *
 * @author jbowens
 * @since May 2013
 */
class UrlValidator implements \JBBCode\InputValidator {

  /**
   * Returns true iff $input is a valid url.
   *
   * @param $input  the string to validate
   */
  public function validate($input) {
    $valid = filter_var($input, FILTER_VALIDATE_URL);
    return !!$valid;
  }
}

Do you have something else filtering the input on the way in, possibly triggered by the = equal sign?

BenFenner avatar Mar 19 '25 15:03 BenFenner