Skip to content

Commit 7fc0fab

Browse files
sreichelSven Reichel
and
Sven Reichel
authored
Updated lib Net/IDNA2 to latest version (OpenMage#1181)
Co-authored-by: Sven Reichel <sven.reichel@sandstein.de>
1 parent d72fb32 commit 7fc0fab

File tree

1 file changed

+91
-91
lines changed

1 file changed

+91
-91
lines changed

lib/Net/IDNA2.php

Lines changed: 91 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/**
3030
* Encode/decode Internationalized Domain Names.
3131
*
32-
* The class allows to convert internationalized domain names
32+
* The class allows one to convert internationalized domain names
3333
* (see RFC 3490 for details) as they can be used with various registries worldwide
3434
* to be translated between their original (localized) form and their encoded form
3535
* as it will be used in the DNS (Domain Name System).
@@ -53,7 +53,7 @@
5353
* @author Markus Nix <mnix@docuverse.de>
5454
* @author Matthias Sommerfeld <mso@phlylabs.de>
5555
* @author Stefan Neufeind <pear.neufeind@speedpartner.de>
56-
* @version $Id: IDNA2.php 305344 2010-11-14 23:52:42Z neufeind $
56+
* @version $Id$
5757
*/
5858
class Net_IDNA2
5959
{
@@ -2272,38 +2272,38 @@ public function setParams($option, $value = false)
22722272

22732273
foreach ($option as $k => $v) {
22742274
switch ($k) {
2275-
case 'encoding':
2276-
switch ($v) {
2277-
case 'utf8':
2278-
case 'ucs4_string':
2279-
case 'ucs4_array':
2280-
$this->_api_encoding = $v;
2281-
break;
2275+
case 'encoding':
2276+
switch ($v) {
2277+
case 'utf8':
2278+
case 'ucs4_string':
2279+
case 'ucs4_array':
2280+
$this->_api_encoding = $v;
2281+
break;
22822282

2283-
default:
2284-
throw new InvalidArgumentException('Set Parameter: Unknown parameter '.$v.' for option '.$k);
2285-
}
2283+
default:
2284+
throw new InvalidArgumentException('Set Parameter: Unknown parameter '.$v.' for option '.$k);
2285+
}
22862286

2287-
break;
2287+
break;
22882288

2289-
case 'overlong':
2290-
$this->_allow_overlong = ($v) ? true : false;
2291-
break;
2289+
case 'overlong':
2290+
$this->_allow_overlong = ($v) ? true : false;
2291+
break;
22922292

2293-
case 'strict':
2294-
$this->_strict_mode = ($v) ? true : false;
2295-
break;
2293+
case 'strict':
2294+
$this->_strict_mode = ($v) ? true : false;
2295+
break;
22962296

2297-
case 'version':
2298-
if (in_array($v, array('2003', '2008'))) {
2299-
$this->_version = $v;
2300-
} else {
2301-
throw new InvalidArgumentException('Set Parameter: Invalid parameter '.$v.' for option '.$k);
2302-
}
2303-
break;
2297+
case 'version':
2298+
if (in_array($v, array('2003', '2008'))) {
2299+
$this->_version = $v;
2300+
} else {
2301+
throw new InvalidArgumentException('Set Parameter: Invalid parameter '.$v.' for option '.$k);
2302+
}
2303+
break;
23042304

2305-
default:
2306-
return false;
2305+
default:
2306+
return false;
23072307
}
23082308
}
23092309

@@ -2327,15 +2327,15 @@ public function encode($decoded, $one_time_encoding = false)
23272327
// Forcing conversion of input to UCS4 array
23282328
// If one time encoding is given, use this, else the objects property
23292329
switch (($one_time_encoding) ? $one_time_encoding : $this->_api_encoding) {
2330-
case 'utf8':
2331-
$decoded = $this->_utf8_to_ucs4($decoded);
2332-
break;
2333-
case 'ucs4_string':
2334-
$decoded = $this->_ucs4_string_to_ucs4($decoded);
2335-
case 'ucs4_array': // No break; before this line. Catch case, but do nothing
2336-
break;
2337-
default:
2338-
throw new InvalidArgumentException('Unsupported input format');
2330+
case 'utf8':
2331+
$decoded = $this->_utf8_to_ucs4($decoded);
2332+
break;
2333+
case 'ucs4_string':
2334+
$decoded = $this->_ucs4_string_to_ucs4($decoded);
2335+
case 'ucs4_array': // No break; before this line. Catch case, but do nothing
2336+
break;
2337+
default:
2338+
throw new InvalidArgumentException('Unsupported input format');
23392339
}
23402340

23412341
// No input, no output, what else did you expect?
@@ -2349,35 +2349,35 @@ public function encode($decoded, $one_time_encoding = false)
23492349
foreach ($decoded as $k => $v) {
23502350
// Make sure to use just the plain dot
23512351
switch($v) {
2352-
case 0x3002:
2353-
case 0xFF0E:
2354-
case 0xFF61:
2355-
$decoded[$k] = 0x2E;
2352+
case 0x3002:
2353+
case 0xFF0E:
2354+
case 0xFF61:
2355+
$decoded[$k] = 0x2E;
23562356
// It's right, no break here
23572357
// The codepoints above have to be converted to dots anyway
23582358

2359-
// Stumbling across an anchoring character
2360-
case 0x2E:
2361-
case 0x2F:
2362-
case 0x3A:
2363-
case 0x3F:
2364-
case 0x40:
2365-
// Neither email addresses nor URLs allowed in strict mode
2366-
if ($this->_strict_mode) {
2367-
throw new InvalidArgumentException('Neither email addresses nor URLs are allowed in strict mode.');
2368-
}
2369-
// Skip first char
2370-
if ($k) {
2371-
$encoded = '';
2372-
$encoded = $this->_encode(array_slice($decoded, $last_begin, (($k)-$last_begin)));
2373-
if ($encoded) {
2374-
$output .= $encoded;
2375-
} else {
2376-
$output .= $this->_ucs4_to_utf8(array_slice($decoded, $last_begin, (($k)-$last_begin)));
2359+
// Stumbling across an anchoring character
2360+
case 0x2E:
2361+
case 0x2F:
2362+
case 0x3A:
2363+
case 0x3F:
2364+
case 0x40:
2365+
// Neither email addresses nor URLs allowed in strict mode
2366+
if ($this->_strict_mode) {
2367+
throw new InvalidArgumentException('Neither email addresses nor URLs are allowed in strict mode.');
23772368
}
2378-
$output .= chr($decoded[$k]);
2379-
}
2380-
$last_begin = $k + 1;
2369+
// Skip first char
2370+
if ($k) {
2371+
$encoded = '';
2372+
$encoded = $this->_encode(array_slice($decoded, $last_begin, (($k)-$last_begin)));
2373+
if ($encoded) {
2374+
$output .= $encoded;
2375+
} else {
2376+
$output .= $this->_ucs4_to_utf8(array_slice($decoded, $last_begin, (($k)-$last_begin)));
2377+
}
2378+
$output .= chr($decoded[$k]);
2379+
}
2380+
$last_begin = $k + 1;
23812381
}
23822382
}
23832383
// Catch the rest of the string
@@ -2415,18 +2415,18 @@ public function decode($input, $one_time_encoding = false)
24152415
// Optionally set
24162416
if ($one_time_encoding) {
24172417
switch ($one_time_encoding) {
2418-
case 'utf8':
2419-
case 'ucs4_string':
2420-
case 'ucs4_array':
2421-
break;
2422-
default:
2423-
throw new InvalidArgumentException('Unknown encoding '.$one_time_encoding);
2418+
case 'utf8':
2419+
case 'ucs4_string':
2420+
case 'ucs4_array':
2421+
break;
2422+
default:
2423+
throw new InvalidArgumentException('Unknown encoding '.$one_time_encoding);
24242424
}
24252425
}
24262426
// Make sure to drop any newline characters around
24272427
$input = trim($input);
24282428

2429-
// Negotiate input and try to determine, wether it is a plain string,
2429+
// Negotiate input and try to determine, whether it is a plain string,
24302430
// an email address or something like a complete URL
24312431
if (strpos($input, '@')) { // Maybe it is an email address
24322432
// No no in strict mode
@@ -2472,17 +2472,17 @@ public function decode($input, $one_time_encoding = false)
24722472
// The output is UTF-8 by default, other output formats need conversion here
24732473
// If one time encoding is given, use this, else the objects property
24742474
switch (($one_time_encoding) ? $one_time_encoding : $this->_api_encoding) {
2475-
case 'utf8':
2476-
return $return;
2477-
break;
2478-
case 'ucs4_string':
2479-
return $this->_ucs4_to_ucs4_string($this->_utf8_to_ucs4($return));
2480-
break;
2481-
case 'ucs4_array':
2482-
return $this->_utf8_to_ucs4($return);
2483-
break;
2484-
default:
2485-
throw new InvalidArgumentException('Unsupported output format');
2475+
case 'utf8':
2476+
return $return;
2477+
break;
2478+
case 'ucs4_string':
2479+
return $this->_ucs4_to_ucs4_string($this->_utf8_to_ucs4($return));
2480+
break;
2481+
case 'ucs4_array':
2482+
return $this->_utf8_to_ucs4($return);
2483+
break;
2484+
default:
2485+
throw new InvalidArgumentException('Unsupported output format');
24862486
}
24872487
}
24882488

@@ -2678,7 +2678,7 @@ private function _decode($encoded)
26782678
return false;
26792679
}
26802680

2681-
// Find last occurence of the delimiter
2681+
// Find last occurrence of the delimiter
26822682
$delim_pos = strrpos($encoded, '-');
26832683

26842684
if ($delim_pos > self::_byteLength($this->_punycode_prefix)) {
@@ -2700,7 +2700,7 @@ private function _decode($encoded)
27002700

27012701
for ($enco_idx = ($delim_pos)? ($delim_pos + 1) : 0; $enco_idx < $enco_len; ++$deco_len) {
27022702
for ($old_idx = $idx, $w = 1, $k = $this->_base; 1 ; $k += $this->_base) {
2703-
$digit = $this->_decodeDigit($encoded{$enco_idx++});
2703+
$digit = $this->_decodeDigit($encoded[$enco_idx++]);
27042704
$idx += $digit * $w;
27052705

27062706
$t = ($k <= $bias) ?
@@ -2796,7 +2796,7 @@ private function _nameprep($input)
27962796

27972797
// Walking through the input array, performing the required steps on each of
27982798
// the input chars and putting the result into the output array
2799-
// While mapping required chars we apply the cannonical ordering
2799+
// While mapping required chars we apply the canonical ordering
28002800

28012801
foreach ($input as $v) {
28022802
// Map to nothing == skip that code point
@@ -2988,7 +2988,7 @@ private function _getCombiningClass($char)
29882988
}
29892989

29902990
/**
2991-
* Apllies the cannonical ordering of a decomposed UCS4 sequence.
2991+
* Apllies the canonical ordering of a decomposed UCS4 sequence.
29922992
*
29932993
* @param array $input Decomposed UCS4 sequence
29942994
*
@@ -3112,9 +3112,9 @@ private function _utf8_to_ucs4($input)
31123112
$mode = 'next';
31133113
$test = 'none';
31143114
for ($k = 0; $k < $inp_len; ++$k) {
3115-
$v = ord($input{$k}); // Extract byte from input string
3115+
$v = ord($input[$k]); // Extract byte from input string
31163116

3117-
if ($v < 128) { // We found an ASCII char - put into stirng as is
3117+
if ($v < 128) { // We found an ASCII char - put into string as is
31183118
$output[$out_len] = $v;
31193119
++$out_len;
31203120
if ('add' == $mode) {
@@ -3279,7 +3279,7 @@ private function _ucs4_string_to_ucs4($input)
32793279
$out_len++;
32803280
$output[$out_len] = 0;
32813281
}
3282-
$output[$out_len] += ord($input{$i}) << (8 * (3 - ($i % 4) ) );
3282+
$output[$out_len] += ord($input[$i]) << (8 * (3 - ($i % 4) ) );
32833283
}
32843284
return $output;
32853285
}
@@ -3365,7 +3365,7 @@ private static function _byteLength($string)
33653365
* @return Net_IDNA2
33663366
* @access public
33673367
*/
3368-
function getInstance($params = array())
3368+
public static function getInstance($params = array())
33693369
{
33703370
return new Net_IDNA2($params);
33713371
}
@@ -3377,12 +3377,12 @@ function getInstance($params = array())
33773377
* only creating a new instance if no IDNA instance with the same
33783378
* parameters currently exists.
33793379
*
3380-
* @param array $params Set of paramaters
3380+
* @param array $params Set of parameters
33813381
*
33823382
* @return object Net_IDNA2
33833383
* @access public
33843384
*/
3385-
function singleton($params = array())
3385+
public static function singleton($params = array())
33863386
{
33873387
static $instances;
33883388
if (!isset($instances)) {
@@ -3399,4 +3399,4 @@ function singleton($params = array())
33993399
// }}}
34003400
}
34013401

3402-
?>
3402+
?>

0 commit comments

Comments
 (0)