Development

Changeset 10514

You must first sign up to be able to contribute.

Changeset 10514

Show
Ignore:
Timestamp:
07/30/08 17:37:02 (4 months ago)
Author:
hartym
Message:

Fixed the way sfToolkit was using a PHP «feature» to treat strings as array, though returning the first character of string instead of the default value

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/util/sfToolkit.class.php

    r9588 r10514  
    564564        return $default; 
    565565      } 
    566       $array = $array[substr($name, $pos + 1, $end - $pos - 1)]; 
    567       $offset = $end; 
     566      else if (is_array($array)) 
     567      { 
     568        $array = $array[substr($name, $pos + 1, $end - $pos - 1)]; 
     569        $offset = $end; 
     570      } 
     571      else 
     572      { 
     573        return $default; 
     574      } 
    568575    } 
    569576 
     
    604611        return false; 
    605612      } 
    606       $array = $array[substr($name, $pos + 1, $end - $pos - 1)]; 
    607       $offset = $end; 
     613      else if (is_array($array)) 
     614      { 
     615        $array = $array[substr($name, $pos + 1, $end - $pos - 1)]; 
     616        $offset = $end; 
     617      } 
     618      else 
     619      { 
     620        return false; 
     621      } 
    608622    } 
    609623 
     
    658672        return $default; 
    659673      } 
    660  
    661       $parent = &$value; 
    662       $key = substr($name, $pos + 1, $end - $pos - 1); 
    663       $value = &$value[$key]; 
    664       $offset = $end; 
     674      else if (is_array($value)) 
     675      { 
     676        $parent = &$value; 
     677        $key = substr($name, $pos + 1, $end - $pos - 1); 
     678        $value = &$value[$key]; 
     679        $offset = $end; 
     680      } 
     681      else 
     682      { 
     683        return $default; 
     684      } 
    665685    } 
    666686 
  • branches/1.1/test/unit/util/sfToolkitTest.php

    r8532 r10514  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(99, new lime_output_color()); 
     13$t = new lime_test(103, new lime_output_color()); 
    1414 
    1515// ::stringToArray() 
     
    197197    'bar', 
    198198  ), 
     199  'simple' => 'string', 
    199200); 
    200201 
     
    214215$t->is(sfToolkit::hasArrayValueForPath($arr, 'bar[1]'), true, '::hasArrayValueForPath() can take an array indexed by integer'); 
    215216$t->is(sfToolkit::hasArrayValueForPath($arr, 'bar[2]'), false, '::hasArrayValueForPath() can take an array indexed by integer'); 
     217 
     218$t->is(sfToolkit::hasArrayValueForPath($arr, 'foo[bar][baz][booze]'), false, '::hasArrayValueForPath() is not fooled by php mistaking strings and array'); 
    216219 
    217220// ::getArrayValueForPath() 
     
    234237$t->is(sfToolkit::getArrayValueForPath($arr, 'bar[2]'), null, '::getArrayValueForPath() can take an array indexed by integer'); 
    235238$t->is(sfToolkit::getArrayValueForPath($arr, 'bar[2]', 'foo'), 'foo', '::getArrayValueForPath() can take an array indexed by integer'); 
     239 
     240$t->is(sfToolkit::getArrayValueForPath($arr, 'foo[bar][baz][booze]'), null, '::getArrayValueForPath() is not fooled by php mistaking strings and array'); 
    236241 
    237242// ::removeArrayValueForPath() 
     
    248253    'bar', 
    249254  ), 
     255  'simple' => 'string', 
    250256), '::removeArrayValueForPath() removes a key'); 
    251257$t->is(sfToolkit::removeArrayValueForPath($arr, 'barfoo'), null, '::removeArrayValueForPath() returns null if the key does not exist'); 
    252258$t->is(sfToolkit::removeArrayValueForPath($arr, 'barfoo', 'bar'), 'bar', '::removeArrayValueForPath() takes the default value as a third argument'); 
     259$t->is(sfToolkit::removeArrayValueForPath($arr, 'foo[bar][baz][booze]'), null, '::removeArrayValueForPath() is not fooled by php mistaking strings and array'); 
     260$t->is(sfToolkit::removeArrayValueForPath($arr, 'foo[simple][bad]'), null, '::removeArrayValueForPath() is not fooled by php mistaking strings and array'); 
    253261 
    254262$t->is(sfToolkit::removeArrayValueForPath($arr, 'foo[bar][baz]'), 'foo bar', '::removeArrayValueForPath() works with deep paths'); 
     
    262270    'bar', 
    263271  ), 
     272  'simple' => 'string', 
    264273), '::removeArrayValueForPath() works with deep paths');