Fix Encode: remove str to lower
Check code style
Этот коммит содержится в:
родитель
c4ec0e7e6e
Коммит
1463f60635
79
idna.php
79
idna.php
@ -64,8 +64,6 @@ function EncodePunycodeIDN( $value )
|
|||||||
$mb_internal_enc = mb_internal_encoding();
|
$mb_internal_enc = mb_internal_encoding();
|
||||||
mb_internal_encoding( "UTF-8" );
|
mb_internal_encoding( "UTF-8" );
|
||||||
|
|
||||||
$value = mb_strtolower( $value );
|
|
||||||
|
|
||||||
/* http://tools.ietf.org/html/rfc3492#section-6.3 */
|
/* http://tools.ietf.org/html/rfc3492#section-6.3 */
|
||||||
$n = 0x80;
|
$n = 0x80;
|
||||||
$delta = 0;
|
$delta = 0;
|
||||||
@ -162,7 +160,7 @@ function EncodePunycodeIDN( $value )
|
|||||||
|
|
||||||
$output[] = chr( ( $q + 22 + 75 * ( $q < 26 ) ) );
|
$output[] = chr( ( $q + 22 + 75 * ( $q < 26 ) ) );
|
||||||
/* http://tools.ietf.org/html/rfc3492#section-6.1 */
|
/* http://tools.ietf.org/html/rfc3492#section-6.1 */
|
||||||
$delta = ( $h == $b )?$delta/700:$delta>>1;
|
$delta = ( $h == $b ) ? $delta / 700 : $delta>>1;
|
||||||
|
|
||||||
$delta += intval( $delta / ( $h + 1 ) );
|
$delta += intval( $delta / ( $h + 1 ) );
|
||||||
|
|
||||||
@ -199,24 +197,24 @@ function EncodePunycodeIDN( $value )
|
|||||||
function DecodePunycodeIDN($value)
|
function DecodePunycodeIDN($value)
|
||||||
{
|
{
|
||||||
/* search subdomains */
|
/* search subdomains */
|
||||||
$sub_domain = explode('.', $value);
|
$sub_domain = explode( '.', $value );
|
||||||
if (count($sub_domain)>1){
|
if ( count( $sub_domain ) > 1 ) {
|
||||||
$sub_result='';
|
$sub_result = '';
|
||||||
foreach ($sub_domain as $sub_value) {
|
foreach ( $sub_domain as $sub_value ) {
|
||||||
$sub_result .= '.'.DecodePunycodeIDN($sub_value);
|
$sub_result .= '.' . DecodePunycodeIDN( $sub_value );
|
||||||
}
|
}
|
||||||
return substr($sub_result,1);
|
return substr( $sub_result, 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* search prefix */
|
/* search prefix */
|
||||||
if (substr($value,0,4)!='xn--')
|
if ( substr( $value, 0, 4 ) != 'xn--' )
|
||||||
{
|
{
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$bad_input=$value;
|
$bad_input = $value;
|
||||||
$value=substr($value,4);
|
$value = substr( $value, 4 );
|
||||||
}
|
}
|
||||||
|
|
||||||
$n = 0x80;
|
$n = 0x80;
|
||||||
@ -225,13 +223,13 @@ function DecodePunycodeIDN($value)
|
|||||||
$output = array();
|
$output = array();
|
||||||
|
|
||||||
/* search delimeter */
|
/* search delimeter */
|
||||||
$d = strrpos($value, '-');
|
$d = strrpos( $value, '-' );
|
||||||
|
|
||||||
if ($d > 0) {
|
if ( $d > 0 ) {
|
||||||
for ( $j = 0; $j < $d; ++$j) {
|
for ( $j = 0; $j < $d; ++$j) {
|
||||||
$c = $value[$j];
|
$c = $value[ $j ];
|
||||||
$output[]=$c;
|
$output[] = $c;
|
||||||
if ($c > 0x7F)
|
if ( $c > 0x7F )
|
||||||
{
|
{
|
||||||
return $bad_input;
|
return $bad_input;
|
||||||
}
|
}
|
||||||
@ -241,38 +239,38 @@ function DecodePunycodeIDN($value)
|
|||||||
$d = 0;
|
$d = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ($d < strlen($value))
|
while ($d < strlen( $value ) )
|
||||||
{
|
{
|
||||||
$oldi = $i;
|
$oldi = $i;
|
||||||
$w = 1;
|
$w = 1;
|
||||||
|
|
||||||
for ($k = 36;; $k += 36)
|
for ($k = 36;; $k += 36)
|
||||||
{
|
{
|
||||||
if ($d == strlen($value))
|
if ( $d == strlen( $value ) )
|
||||||
{
|
{
|
||||||
return $bad_input;
|
return $bad_input;
|
||||||
}
|
}
|
||||||
$c = $value[$d++];
|
$c = $value[ $d++ ];
|
||||||
$c=ord($c);
|
$c = ord( $c );
|
||||||
|
|
||||||
$digit=($c - 48 < 10) ? $c - 22 :
|
$digit = ( $c - 48 < 10) ? $c - 22 :
|
||||||
(
|
(
|
||||||
($c - 65 < 26) ? $c - 65 :
|
( $c - 65 < 26 ) ? $c - 65 :
|
||||||
(
|
(
|
||||||
($c - 97 < 26) ? $c - 97 : 36
|
( $c - 97 < 26 ) ? $c - 97 : 36
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
if ($digit > (0x10FFFF - $i) / $w)
|
if ( $digit > ( 0x10FFFF - $i ) / $w )
|
||||||
{
|
{
|
||||||
return $bad_input;
|
return $bad_input;
|
||||||
}
|
}
|
||||||
$i += $digit * $w;
|
$i += $digit * $w;
|
||||||
|
|
||||||
if ($k <= $bias)
|
if ( $k <= $bias )
|
||||||
{
|
{
|
||||||
$t = 1;
|
$t = 1;
|
||||||
}
|
}
|
||||||
elseif ($k >= $bias + 26)
|
elseif ( $k >= $bias + 26 )
|
||||||
{
|
{
|
||||||
$t = 26;
|
$t = 26;
|
||||||
}
|
}
|
||||||
@ -280,41 +278,42 @@ function DecodePunycodeIDN($value)
|
|||||||
{
|
{
|
||||||
$t = $k - $bias;
|
$t = $k - $bias;
|
||||||
}
|
}
|
||||||
if ($digit < $t) {
|
if ( $digit < $t ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$w *= (36 - $t);
|
$w *= ( 36 - $t );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$delta = $i - $oldi;
|
$delta = $i - $oldi;
|
||||||
|
|
||||||
/* http://tools.ietf.org/html/rfc3492#section-6.1 */
|
/* http://tools.ietf.org/html/rfc3492#section-6.1 */
|
||||||
$delta = ($oldi == 0)?$delta/700:$delta>>1;
|
$delta = ( $oldi == 0 ) ? $delta/700 : $delta>>1;
|
||||||
|
|
||||||
$count_output_plus_one=count($output)+1;
|
$count_output_plus_one = count( $output ) + 1;
|
||||||
$delta += ($delta / ($count_output_plus_one+1));
|
$delta += ( $delta / ( $count_output_plus_one + 1 ) );
|
||||||
|
|
||||||
$k2 = 0;
|
$k2 = 0;
|
||||||
while ($delta > 455)
|
while ( $delta > 455 )
|
||||||
{
|
{
|
||||||
$delta /= 35;
|
$delta /= 35;
|
||||||
$k2 += 36;
|
$k2 += 36;
|
||||||
}
|
}
|
||||||
$bias= intval($k2 + (36 * $delta) / ($delta + 38));
|
$bias = intval( $k2 + ( 36 * $delta ) / ( $delta + 38 ) );
|
||||||
/* end section-6.1 */
|
/* end section-6.1 */
|
||||||
if ($i / $count_output_plus_one > 0x10FFFF - $n)
|
if ( $i / $count_output_plus_one > 0x10FFFF - $n )
|
||||||
{
|
{
|
||||||
return $bad_input;
|
return $bad_input;
|
||||||
}
|
}
|
||||||
$n += intval($i / $count_output_plus_one);
|
$n += intval( $i / $count_output_plus_one );
|
||||||
$i = intval($i % $count_output_plus_one);
|
$i = intval( $i % $count_output_plus_one );
|
||||||
array_splice($output, $i, 0,
|
array_splice( $output, $i, 0,
|
||||||
html_entity_decode('&#'.$n.';',ENT_NOQUOTES,'UTF-8')
|
html_entity_decode( '&#' . $n . ';', ENT_NOQUOTES, 'UTF-8' )
|
||||||
);
|
);
|
||||||
++$i;
|
++$i;
|
||||||
}
|
}
|
||||||
return implode('', $output);
|
|
||||||
|
return implode( '', $output );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Загрузка…
Ссылка в новой задаче
Block a user