diff options
| -rw-r--r-- | phpBB/phpbb/textformatter/s9e/link_helper.php | 17 | ||||
| -rw-r--r-- | tests/text_formatter/s9e/default_formatting_test.php | 4 | 
2 files changed, 20 insertions, 1 deletions
diff --git a/phpBB/phpbb/textformatter/s9e/link_helper.php b/phpBB/phpbb/textformatter/s9e/link_helper.php index 76948159ba..0f44603dec 100644 --- a/phpBB/phpbb/textformatter/s9e/link_helper.php +++ b/phpBB/phpbb/textformatter/s9e/link_helper.php @@ -47,7 +47,7 @@ class link_helper  		// Only create a LINK_TEXT tag if the start tag is paired with an end  		// tag, which is the case with tags from the Autolink plugins and with  		// the [url] BBCode when its content is used for the URL -		if (!$tag->getEndTag()) +		if (!$tag->getEndTag() || !$this->should_shorten($tag, $parser->getText()))  		{  			return true;  		} @@ -65,6 +65,21 @@ class link_helper  	}  	/** +	* Test whether we should shorten this tag's text +	* +	* Will test whether the tag either does not use any markup or uses a single +	* [url] BBCode +	* +	* @param  \s9e\TextFormatter\Parser\Tag $tag  URL tag +	* @param  string                        $text Original text +	* @return bool +	*/ +	protected function should_shorten(\s9e\TextFormatter\Parser\Tag $tag, $text) +	{ +		return ($tag->getLen() === 0 || strtolower(substr($text, $tag->getPos(), $tag->getLen())) === '[url]'); +	} + +	/**  	* Remove the board's root URL from a the start of a string  	*  	* @param  \s9e\TextFormatter\Parser\Tag $tag       LINK_TEXT tag diff --git a/tests/text_formatter/s9e/default_formatting_test.php b/tests/text_formatter/s9e/default_formatting_test.php index fc6b0a65fa..1f7df15434 100644 --- a/tests/text_formatter/s9e/default_formatting_test.php +++ b/tests/text_formatter/s9e/default_formatting_test.php @@ -248,6 +248,10 @@ class phpbb_textformatter_s9e_default_formatting_test extends phpbb_test_case  				'<a href="http://example.org/0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0" class="postlink">http://example.org/0xxxxxxxxxxxxxxxxxxx ... xxxxxxxxx0</a>'  			),  			array( +				'[URL]http://example.org/0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0[/url]', +				'<a href="http://example.org/0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0" class="postlink">http://example.org/0xxxxxxxxxxxxxxxxxxx ... xxxxxxxxx0</a>' +			), +			array(  				'[url=http://example.org/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx]xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx[/url]',  				'<a href="http://example.org/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" class="postlink">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</a>'  			),  | 
