Skip to content
This repository has been archived by the owner on Jan 8, 2021. It is now read-only.

Commit

Permalink
cleanup input EOL to work around https://bugs.php.net/65732
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Oct 3, 2013
1 parent e4bd68c commit 5c4e5ce
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions class/Patchwork/Utf8/Bootup.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,21 +197,31 @@ static function filterRequestInputs($normalization_form = /* n::NFC = */ 4, $pre
foreach ($a[$i] as &$v)
{
if (is_array($v)) $a[$len++] =& $v;
else if (preg_match('/[\x80-\xFF]/', $v))
else
{
if (n::isNormalized($v, $normalization_form)) $w = '';
else
if (false !== strpos($v, "\r"))
{
$w = n::normalize($v, $normalization_form);
if (false === $w) $v = u::utf8_encode($v);
else $v = $w;
// Workaround https://bugs.php.net/65732
$v = str_replace("\r\n", "\n", $v);
$v = strtr($v, "\r", "\n");
}

if ($v[0] >= "\x80" && false !== $w && isset($pre_lead_comb[0]) && preg_match('/^\p{Mn}/u', $v))
if (preg_match('/[\x80-\xFF]/', $v))
{
// Prevent leading combining chars
// for NFC-safe concatenations.
$v = $pre_lead_comb . $v;
if (n::isNormalized($v, $normalization_form)) $w = '';
else
{
$w = n::normalize($v, $normalization_form);
if (false === $w) $v = u::utf8_encode($v);
else $v = $w;
}

if ($v[0] >= "\x80" && false !== $w && isset($pre_lead_comb[0]) && preg_match('/^\p{Mn}/u', $v))
{
// Prevent leading combining chars
// for NFC-safe concatenations.
$v = $pre_lead_comb . $v;
}
}
}
}
Expand Down

0 comments on commit 5c4e5ce

Please sign in to comment.