Skip to content

Commit bc5d976

Browse files
committed
[ticket/14323] Added should_shorten()
Explicitly tests a tag's markup to determine whether a link should be shortened PHPBB3-14323
1 parent bcd5d8b commit bc5d976

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

phpBB/phpbb/textformatter/s9e/link_helper.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function generate_link_text_tag(\s9e\TextFormatter\Parser\Tag $tag, \s9e\
4747
// Only create a LINK_TEXT tag if the start tag is paired with an end
4848
// tag, which is the case with tags from the Autolink plugins and with
4949
// the [url] BBCode when its content is used for the URL
50-
if (!$tag->getEndTag())
50+
if (!$tag->getEndTag() || !$this->should_shorten($tag, $parser->getText()))
5151
{
5252
return true;
5353
}
@@ -64,6 +64,21 @@ public function generate_link_text_tag(\s9e\TextFormatter\Parser\Tag $tag, \s9e\
6464
return true;
6565
}
6666

67+
/**
68+
* Test whether we should shorten this tag's text
69+
*
70+
* Will test whether the tag either does not use any markup or uses a single
71+
* [url] BBCode
72+
*
73+
* @param \s9e\TextFormatter\Parser\Tag $tag URL tag
74+
* @param string $text Original text
75+
* @return bool
76+
*/
77+
protected function should_shorten(\s9e\TextFormatter\Parser\Tag $tag, $text)
78+
{
79+
return ($tag->getLen() === 0 || strtolower(substr($text, $tag->getPos(), $tag->getLen())) === '[url]');
80+
}
81+
6782
/**
6883
* Remove the board's root URL from a the start of a string
6984
*

tests/text_formatter/s9e/default_formatting_test.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ public function get_default_formatting_tests()
247247
'[url]http://example.org/0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0[/url]',
248248
'<a href="http://example.org/0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0" class="postlink">http://example.org/0xxxxxxxxxxxxxxxxxxx ... xxxxxxxxx0</a>'
249249
),
250+
array(
251+
'[URL]http://example.org/0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0[/url]',
252+
'<a href="http://example.org/0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0" class="postlink">http://example.org/0xxxxxxxxxxxxxxxxxxx ... xxxxxxxxx0</a>'
253+
),
250254
array(
251255
'[url=http://example.org/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx]xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx[/url]',
252256
'<a href="http://example.org/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" class="postlink">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</a>'

0 commit comments

Comments
 (0)