Changeset 24527
- Timestamp:
- 11/29/09 15:21:42 (3 years ago)
- Files:
-
- components/yaml/branches/1.0/lib/sfYamlInline.php (modified) (3 diffs)
- components/yaml/branches/1.0/lib/sfYamlParser.php (modified) (1 diff)
- components/yaml/branches/1.0/test/fixtures/sfQuotes.yml (modified) (1 diff)
- components/yaml/branches/1.0/test/sfYamlDumperTest.php (modified) (1 diff)
- components/yaml/branches/1.0/test/sfYamlInlineTest.php (modified) (2 diffs)
- components/yaml/branches/1.0/test/sfYamlParserTest.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
components/yaml/branches/1.0/lib/sfYamlInline.php
r22986 r24527 21 21 class sfYamlInline 22 22 { 23 const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\']*(?:\'\'[^\']*)*)\')'; 24 23 25 /** 24 26 * Convert a YAML string to a PHP array. … … 157 159 // quoted scalar 158 160 $output = self::parseQuotedScalar($scalar, $i); 159 160 // skip next delimiter161 ++$i;162 161 } 163 162 else … … 201 200 static protected function parseQuotedScalar($scalar, &$i) 202 201 { 203 $delimiter = $scalar[$i]; 204 ++$i; 205 $buffer = ''; 206 $len = strlen($scalar); 207 $escaped = '"' == $delimiter ? '\\"' : "''"; 208 209 while ($i < $len) 210 { 211 if (isset($scalar[$i + 1]) && $escaped == $scalar[$i].$scalar[$i + 1]) 212 { 213 $buffer .= $delimiter; 214 ++$i; 215 } 216 else if ($delimiter == $scalar[$i]) 217 { 218 break; 219 } 220 else 221 { 222 $buffer .= $scalar[$i]; 223 } 224 225 ++$i; 226 } 227 228 if ('"' == $delimiter) 202 preg_match('/'.self::REGEX_QUOTED_STRING.'/A', substr($scalar, $i), $match); 203 204 $output = stripcslashes(substr($match[0], 1, strlen($match[0]) - 2)); 205 206 if ('"' == $scalar[$i]) 229 207 { 230 208 // evaluate the string 231 $buffer = str_replace(array('\\n', '\\r'), array("\n", "\r"), $buffer); 232 } 233 234 return $buffer; 209 $output = str_replace(array('\\n', '\\r'), array("\n", "\r"), $output); 210 } 211 else 212 { 213 // unescape ' 214 $output = str_replace('\'\'', '\'', $output); 215 } 216 217 $i += strlen($match[0]); 218 219 return $output; 235 220 } 236 221 components/yaml/branches/1.0/lib/sfYamlParser.php
r23504 r24527 103 103 } 104 104 } 105 else if (preg_match('#^(?P<key> [^ ].*?) *\:(\s+(?P<value>.+?))?\s*$#', $this->currentLine, $values))105 else if (preg_match('#^(?P<key>'.sfYamlInline::REGEX_QUOTED_STRING.'|[^ ].*?) *\:(\s+(?P<value>.+?))?\s*$#', $this->currentLine, $values)) 106 106 { 107 107 $key = sfYamlInline::parseScalar($values['key']); components/yaml/branches/1.0/test/fixtures/sfQuotes.yml
r21431 r24527 7 7 php: | 8 8 array('foo' => '| bar') 9 --- 10 test: A key can be a quoted string 11 brief: > 12 A key can be a quoted string 13 yaml: | 14 "foo1": bar 15 'foo2': bar 16 "foo \" bar": bar 17 'foo '' bar': bar 18 'foo3: ': bar 19 "foo4: ": bar 20 foo5: { "foo \" bar: ": bar, 'foo '' bar: ': bar } 21 php: | 22 array( 23 'foo1' => 'bar', 24 'foo2' => 'bar', 25 'foo " bar' => 'bar', 26 'foo \' bar' => 'bar', 27 'foo3: ' => 'bar', 28 'foo4: ' => 'bar', 29 'foo5' => array( 30 'foo " bar: ' => 'bar', 31 'foo \' bar: ' => 'bar', 32 ), 33 ) components/yaml/branches/1.0/test/sfYamlDumperTest.php
r23743 r24527 16 16 sfYaml::setSpecVersion('1.1'); 17 17 18 $t = new lime_test(14 3);18 $t = new lime_test(144); 19 19 20 20 $parser = new sfYamlParser(); components/yaml/branches/1.0/test/sfYamlInlineTest.php
r21883 r24527 15 15 sfYaml::setSpecVersion('1.1'); 16 16 17 $t = new lime_test(1 18);17 $t = new lime_test(124); 18 18 19 19 // ::load() … … 56 56 '{ foo : bar, bar : foo, false : false, null : null, integer : 12 }' => array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12), 57 57 '{foo: \'bar\', bar: \'foo: bar\'}' => array('foo' => 'bar', 'bar' => 'foo: bar'), 58 '{\'foo\': \'bar\', "bar": \'foo: bar\'}' => array('foo' => 'bar', 'bar' => 'foo: bar'), 59 '{\'foo\'\'\': \'bar\', "bar\"": \'foo: bar\'}' => array('foo\'' => 'bar', "bar\"" => 'foo: bar'), 60 '{\'foo: \': \'bar\', "bar: ": \'foo: bar\'}' => array('foo: ' => 'bar', "bar: " => 'foo: bar'), 58 61 59 62 // nested sequences and mappings components/yaml/branches/1.0/test/sfYamlParserTest.php
r23743 r24527 15 15 sfYaml::setSpecVersion('1.1'); 16 16 17 $t = new lime_test(14 3);17 $t = new lime_test(144); 18 18 19 19 $parser = new sfYamlParser();