Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing JFilterInput adding byte offsets to character offset #15966

Merged
merged 4 commits into from May 12, 2017
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions libraries/joomla/filter/input.php
Expand Up @@ -926,8 +926,10 @@ protected function cleanTags($source)
// Find position of equal and open quotes ignoring
if (preg_match('#\s*=\s*\"#', $fromSpace, $matches, PREG_OFFSET_CAPTURE))
{
// We have found an attribute, convert its byte position to a UTF-8 string length, using non-multibyte substr()
$stringBeforeAttr = substr($fromSpace, 0, $matches[0][1]);
$startAttPosition = StringHelper::strlen($stringBeforeAttr);
$startAtt = $matches[0][0];
$startAttPosition = $matches[0][1];
$closeQuotes = StringHelper::strpos(
StringHelper::substr($fromSpace, ($startAttPosition + StringHelper::strlen($startAtt))), '"'
) + $startAttPosition + StringHelper::strlen($startAtt);
Expand Down Expand Up @@ -1080,8 +1082,11 @@ protected function escapeAttributeValues($source)
*/
while (preg_match('#<[^>]*?=\s*?(\"|\')#s', $remainder, $matches, PREG_OFFSET_CAPTURE))
{
// We have found an opening quote, convert its byte position to a UTF-8 string length, using non-multibyte substr()
$stringBeforeQuote = substr($remainder, 0, $matches[1][1]);
$quotePosition = StringHelper::strlen($stringBeforeQuote);

// Get the portion before the attribute value
$quotePosition = $matches[0][1];
$nextBefore = $quotePosition + StringHelper::strlen($matches[0][0]);

/*
Expand All @@ -1092,9 +1097,12 @@ protected function escapeAttributeValues($source)
$pregMatch = ($quote == '"') ? '#(\"\s*/\s*>|\"\s*>|\"\s+|\"$)#' : "#(\'\s*/\s*>|\'\s*>|\'\s+|\'$)#";

// Get the portion after attribute value
if (preg_match($pregMatch, StringHelper::substr($remainder, $nextBefore), $matches, PREG_OFFSET_CAPTURE))
$attributeValueRemainder = StringHelper::substr($remainder, $nextBefore);
if (preg_match($pregMatch, $attributeValueRemainder, $matches, PREG_OFFSET_CAPTURE))
{
// We have a closing quote
// We have a closing quote, convert its byte position to a UTF-8 string length, using non-multibyte substr()
$stringBeforeQuote = substr($attributeValueToEnd, 0, $matches[0][1]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$attributeValueToEnd is undefined.... did you mean $attributeValueRemainder?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, i meant $attributeValueRemainder, i marginally got some time to make the PR before getting some very much needed sleep, lol

$closeQuoteChars = StringHelper::strlen($stringBeforeQuote);
$nextAfter = $nextBefore + $matches[0][1];
}
else
Expand Down