Skip to content

Commit 8197231

Browse files
author
Phil Sturgeon
committed
Merge pull request chriskacerguis#136 from sekati/master
Update CodeIgniter files to 2.1.2 (Jun 29th, 2012 release)
2 parents 0b871cf + 03a3d31 commit 8197231

24 files changed

+414
-173
lines changed

application/config/mimes.php

100755100644
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
$mimes = array( 'hqx' => 'application/mac-binhex40',
1212
'cpt' => 'application/mac-compactpro',
13-
'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel'),
13+
'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel'),
1414
'bin' => 'application/macbinary',
1515
'dms' => 'application/octet-stream',
1616
'lha' => 'application/octet-stream',
@@ -56,7 +56,7 @@
5656
'midi' => 'audio/midi',
5757
'mpga' => 'audio/mpeg',
5858
'mp2' => 'audio/mpeg',
59-
'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3'),
59+
'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'),
6060
'aif' => 'audio/x-aiff',
6161
'aiff' => 'audio/x-aiff',
6262
'aifc' => 'audio/x-aiff',
@@ -65,8 +65,8 @@
6565
'rpm' => 'audio/x-pn-realaudio-plugin',
6666
'ra' => 'audio/x-realaudio',
6767
'rv' => 'video/vnd.rn-realvideo',
68-
'wav' => 'audio/x-wav',
69-
'bmp' => 'image/bmp',
68+
'wav' => array('audio/x-wav', 'audio/wave', 'audio/wav'),
69+
'bmp' => array('image/bmp', 'image/x-windows-bmp'),
7070
'gif' => 'image/gif',
7171
'jpeg' => array('image/jpeg', 'image/pjpeg'),
7272
'jpg' => array('image/jpeg', 'image/pjpeg'),
@@ -93,13 +93,14 @@
9393
'avi' => 'video/x-msvideo',
9494
'movie' => 'video/x-sgi-movie',
9595
'doc' => 'application/msword',
96-
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
97-
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
96+
'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip'),
97+
'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip'),
9898
'word' => array('application/msword', 'application/octet-stream'),
9999
'xl' => 'application/excel',
100-
'eml' => 'message/rfc822'
100+
'eml' => 'message/rfc822',
101+
'json' => array('application/json', 'text/json')
101102
);
102103

103104

104105
/* End of file mimes.php */
105-
/* Location: ./application/config/mimes.php */
106+
/* Location: ./application/config/mimes.php */

system/core/CodeIgniter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* @var string
3434
*
3535
*/
36-
define('CI_VERSION', '2.1.0');
36+
define('CI_VERSION', '2.1.2');
3737

3838
/**
3939
* CodeIgniter Branch (Core = TRUE, Reactor = FALSE)

system/core/Input.php

Lines changed: 131 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,18 +365,70 @@ function ip_address()
365365
/**
366366
* Validate IP Address
367367
*
368+
* @access public
369+
* @param string
370+
* @param string ipv4 or ipv6
371+
* @return bool
372+
*/
373+
public function valid_ip($ip, $which = '')
374+
{
375+
$which = strtolower($which);
376+
377+
// First check if filter_var is available
378+
if (is_callable('filter_var'))
379+
{
380+
switch ($which) {
381+
case 'ipv4':
382+
$flag = FILTER_FLAG_IPV4;
383+
break;
384+
case 'ipv6':
385+
$flag = FILTER_FLAG_IPV6;
386+
break;
387+
default:
388+
$flag = '';
389+
break;
390+
}
391+
392+
return (bool) filter_var($ip, FILTER_VALIDATE_IP, $flag);
393+
}
394+
395+
if ($which !== 'ipv6' && $which !== 'ipv4')
396+
{
397+
if (strpos($ip, ':') !== FALSE)
398+
{
399+
$which = 'ipv6';
400+
}
401+
elseif (strpos($ip, '.') !== FALSE)
402+
{
403+
$which = 'ipv4';
404+
}
405+
else
406+
{
407+
return FALSE;
408+
}
409+
}
410+
411+
$func = '_valid_'.$which;
412+
return $this->$func($ip);
413+
}
414+
415+
// --------------------------------------------------------------------
416+
417+
/**
418+
* Validate IPv4 Address
419+
*
368420
* Updated version suggested by Geert De Deckere
369421
*
370-
* @access public
422+
* @access protected
371423
* @param string
372-
* @return string
424+
* @return bool
373425
*/
374-
function valid_ip($ip)
426+
protected function _valid_ipv4($ip)
375427
{
376428
$ip_segments = explode('.', $ip);
377429

378430
// Always 4 segments needed
379-
if (count($ip_segments) != 4)
431+
if (count($ip_segments) !== 4)
380432
{
381433
return FALSE;
382434
}
@@ -385,6 +437,7 @@ function valid_ip($ip)
385437
{
386438
return FALSE;
387439
}
440+
388441
// Check each segment
389442
foreach ($ip_segments as $segment)
390443
{
@@ -401,6 +454,80 @@ function valid_ip($ip)
401454

402455
// --------------------------------------------------------------------
403456

457+
/**
458+
* Validate IPv6 Address
459+
*
460+
* @access protected
461+
* @param string
462+
* @return bool
463+
*/
464+
protected function _valid_ipv6($str)
465+
{
466+
// 8 groups, separated by :
467+
// 0-ffff per group
468+
// one set of consecutive 0 groups can be collapsed to ::
469+
470+
$groups = 8;
471+
$collapsed = FALSE;
472+
473+
$chunks = array_filter(
474+
preg_split('/(:{1,2})/', $str, NULL, PREG_SPLIT_DELIM_CAPTURE)
475+
);
476+
477+
// Rule out easy nonsense
478+
if (current($chunks) == ':' OR end($chunks) == ':')
479+
{
480+
return FALSE;
481+
}
482+
483+
// PHP supports IPv4-mapped IPv6 addresses, so we'll expect those as well
484+
if (strpos(end($chunks), '.') !== FALSE)
485+
{
486+
$ipv4 = array_pop($chunks);
487+
488+
if ( ! $this->_valid_ipv4($ipv4))
489+
{
490+
return FALSE;
491+
}
492+
493+
$groups--;
494+
}
495+
496+
while ($seg = array_pop($chunks))
497+
{
498+
if ($seg[0] == ':')
499+
{
500+
if (--$groups == 0)
501+
{
502+
return FALSE; // too many groups
503+
}
504+
505+
if (strlen($seg) > 2)
506+
{
507+
return FALSE; // long separator
508+
}
509+
510+
if ($seg == '::')
511+
{
512+
if ($collapsed)
513+
{
514+
return FALSE; // multiple collapsed
515+
}
516+
517+
$collapsed = TRUE;
518+
}
519+
}
520+
elseif (preg_match("/[^0-9a-f]/i", $seg) OR strlen($seg) > 4)
521+
{
522+
return FALSE; // invalid segment
523+
}
524+
}
525+
526+
return $collapsed OR $groups == 1;
527+
}
528+
529+
// --------------------------------------------------------------------
530+
404531
/**
405532
* User Agent
406533
*

0 commit comments

Comments
 (0)