Changeset 7922
- Timestamp:
- 03/16/08 21:21:03 (4 months ago)
- Files:
-
- branches/1.1/lib/util/sfYamlInline.class.php (modified) (7 diffs)
- branches/1.1/test/unit/util/sfYamlInlineTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/util/sfYamlInline.class.php
r7898 r7922 60 60 throw new InvalidArgumentException('Unable to dump PHP resources in a YAML file.'); 61 61 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.'); 63 63 case is_array($value): 64 64 return self::dumpArray($value); … … 167 167 else 168 168 { 169 throw new sfException(sprintf('Malformed inline YAML string (%s).', $scalar));169 throw new InvalidArgumentException(sprintf('Malformed inline YAML string (%s).', $scalar)); 170 170 } 171 171 … … 253 253 break; 254 254 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 256 273 --$i; 257 274 } … … 260 277 } 261 278 262 throw new sfException(sprintf('Malformed inline YAML string %s', $sequence));279 throw new InvalidArgumentException(sprintf('Malformed inline YAML string %s', $sequence)); 263 280 } 264 281 … … 327 344 } 328 345 329 throw new sfException(sprintf('Malformed inline YAML string %s', $mapping));346 throw new InvalidArgumentException(sprintf('Malformed inline YAML string %s', $mapping)); 330 347 } 331 348 … … 349 366 case 0 === strpos($scalar, '!str'): 350 367 return (string) substr($scalar, 5); 368 case 0 === strpos($scalar, '! '): 369 return intval(self::parseScalar(substr($scalar, 2))); 351 370 case ctype_digit($scalar): 352 371 return '0' == $scalar[0] ? octdec($scalar) : intval($scalar); … … 358 377 return '0x' == $scalar[0].$scalar[1] ? hexdec($scalar) : floatval($scalar); 359 378 case 0 == strcasecmp($scalar, '.inf'): 379 case 0 == strcasecmp($scalar, '.NaN'): 360 380 return -log(0); 361 381 case 0 == strcasecmp($scalar, '-.inf'): 362 382 return log(0); 363 case preg_match('/^ -?[0-9\,\.]+$/', $scalar):383 case preg_match('/^(-|\+)?[0-9\,\.]+$/', $scalar): 364 384 return floatval(str_replace(',', '', $scalar)); 365 385 case preg_match(self::getTimestampRegex(), $scalar): branches/1.1/test/unit/util/sfYamlInlineTest.php
r7892 r7922 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test( 98, new lime_output_color());13 $t = new lime_test(100, new lime_output_color()); 14 14 15 15 // ::load() … … 60 60 61 61 '[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'))), 62 64 ); 63 65