Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions phpBB/phpbb/textformatter/s9e/factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,12 @@ function ($m)
</xsl:choose>';
$tag->template = '<xsl:choose><xsl:when test="$S_VIEWSMILIES">' . str_replace('class="emoji"', 'class="emoji smilies"', $tag->template) . '</xsl:when><xsl:otherwise><xsl:value-of select="."/></xsl:otherwise></xsl:choose>';

// Reject shortcodes that consist of raw codepoints in hexadecimal such as ":123c:",
// which commonly appear as segments of IPv6 addresses
$tag->filterChain
->append(__NAMESPACE__ . '\\parser::filter_emoji')
->addParameterByName('tagText');

/**
* Modify the s9e\TextFormatter configurator after the default settings are set
*
Expand Down
19 changes: 19 additions & 0 deletions phpBB/phpbb/textformatter/s9e/parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,25 @@ public function set_vars(array $vars)
}
}

/**
* Filter an EMOJI tag to reject shortcodes that consist of raw codepoints
*
* Sequences of hexadecimal digits between colons such as ":123c:" commonly
* appear as segments of IPv6 addresses and should remain plain text rather
* than be rendered as an emoji image
*
* @param Tag $tag The EMOJI tag
* @param string $tag_text Original text consumed by the tag
* @return void
*/
static public function filter_emoji(Tag $tag, $tag_text)
{
if (preg_match('/^:[0-3][0-9a-f]{3,4}(?:-[0-9a-f]{4,5})*:$/D', $tag_text))
{
$tag->invalidate();
}
}

/**
* Filter a flash object's height
*
Expand Down
20 changes: 20 additions & 0 deletions tests/text_formatter/s9e/default_formatting_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,26 @@ function ($container)
$container->get('text_formatter.renderer')->set_viewsmilies(false);
}
),
array(
// PHPBB-17655 - Segments of IPv6 addresses should not be rendered as emoji
'IPv6: 2a09:bac3:616e:123c::1d1:f0',
'IPv6: 2a09:bac3:616e:123c::1d1:f0'
),
array(
'IPv6: 2607:fb90:ec1d:0e17:e0c6:af94:1224:28a8',
'IPv6: 2607:fb90:ec1d:0e17:e0c6:af94:1224:28a8'
),
array(
// Raw codepoint shortcodes are rejected as they cannot be told apart
// from segments of IPv6 addresses
'Codepoints: :264d: :1f600: :1234:',
'Codepoints: :264d: :1f600: :1234:'
),
array(
// Emoji shortnames keep working
'Shortname: :joy:',
'Shortname: <img alt=":joy:" class="emoji smilies" draggable="false" src="//cdn.jsdelivr.net/gh/twitter/twemoji@latest/assets/svg/1f602.svg">'
),
);
}
}
Loading