Development

Changeset 7922

You must first sign up to be able to contribute.

Changeset 7922

Show
Ignore:
Timestamp:
03/16/08 21:21:03 (4 months ago)
Author:
fabien
Message:

fixed some bugs in sfYamlInline (closes #3127)

Files:

Legend:

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

    r7898 r7922  
    6060        throw new InvalidArgumentException('Unable to dump PHP resources in a YAML file.'); 
    6161      case is_object($value): 
    62         throw new sfException('Unable to dump objects to a YAML string.'); 
     62        throw new InvalidArgumentException('Unable to dump objects to a YAML string.'); 
    6363      case is_array($value): 
    6464        return self::dumpArray($value); 
     
    167167      else 
    168168      { 
    169         throw new sfException(sprintf('Malformed inline YAML string (%s).', $scalar)); 
     169        throw new InvalidArgumentException(sprintf('Malformed inline YAML string (%s).', $scalar)); 
    170170      } 
    171171 
     
    253253          break; 
    254254        default: 
    255           $output[] = self::parseScalar($sequence, array(',', ']'), array('"', "'"), $i); 
     255          $isQuoted = in_array($sequence[$i], array('"', "'")); 
     256          $value = self::parseScalar($sequence, array(',', ']'), array('"', "'"), $i); 
     257 
     258          if (!$isQuoted && false !== strpos($value, ':')) 
     259          { 
     260            // embedded mapping? 
     261            try 
     262            { 
     263              $value = self::parseMapping('{'.$value.'}'); 
     264            } 
     265            catch (InvalidArgumentException $e) 
     266            { 
     267              // no, it's not 
     268            } 
     269          } 
     270 
     271          $output[] = $value; 
     272 
    256273          --$i; 
    257274      } 
     
    260277    } 
    261278 
    262     throw new sfException(sprintf('Malformed inline YAML string %s', $sequence)); 
     279    throw new InvalidArgumentException(sprintf('Malformed inline YAML string %s', $sequence)); 
    263280  } 
    264281 
     
    327344    } 
    328345 
    329     throw new sfException(sprintf('Malformed inline YAML string %s', $mapping)); 
     346    throw new InvalidArgumentException(sprintf('Malformed inline YAML string %s', $mapping)); 
    330347  } 
    331348 
     
    349366      case 0 === strpos($scalar, '!str'): 
    350367        return (string) substr($scalar, 5); 
     368      case 0 === strpos($scalar, '! '): 
     369        return intval(self::parseScalar(substr($scalar, 2))); 
    351370      case ctype_digit($scalar): 
    352371        return '0' == $scalar[0] ? octdec($scalar) : intval($scalar); 
     
    358377        return '0x' == $scalar[0].$scalar[1] ? hexdec($scalar) : floatval($scalar); 
    359378      case 0 == strcasecmp($scalar, '.inf'): 
     379      case 0 == strcasecmp($scalar, '.NaN'): 
    360380        return -log(0); 
    361381      case 0 == strcasecmp($scalar, '-.inf'): 
    362382        return log(0); 
    363       case preg_match('/^-?[0-9\,\.]+$/', $scalar): 
     383      case preg_match('/^(-|\+)?[0-9\,\.]+$/', $scalar): 
    364384        return floatval(str_replace(',', '', $scalar)); 
    365385      case preg_match(self::getTimestampRegex(), $scalar): 
  • branches/1.1/test/unit/util/sfYamlInlineTest.php

    r7892 r7922  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(98, new lime_output_color()); 
     13$t = new lime_test(100, new lime_output_color()); 
    1414 
    1515// ::load() 
     
    6060 
    6161  '[foo, {bar: foo, foo: [foo, {bar: foo}]}, [foo, {bar: foo}]]' => array('foo', array('bar' => 'foo', 'foo' => array('foo', array('bar' => 'foo'))), array('foo', array('bar' => 'foo'))), 
     62 
     63  '[foo, bar: { foo: bar }]' => array('foo', '1' => array('bar' => array('foo' => 'bar'))), 
    6264); 
    6365