@@ -51,13 +51,13 @@ public function __construct($offset = 0)
51
51
*/
52
52
public function parse ($ value , $ exceptionOnInvalidType = false , $ objectSupport = false )
53
53
{
54
- $ this ->currentLineNb = -1 ;
55
- $ this ->currentLine = '' ;
56
- $ this ->lines = explode ("\n" , $ this ->cleanup ($ value ));
57
-
58
54
if (!preg_match ('//u ' , $ value )) {
59
55
throw new ParseException ('The YAML value does not appear to be valid UTF-8. ' );
60
56
}
57
+ $ this ->currentLineNb = -1 ;
58
+ $ this ->currentLine = '' ;
59
+ $ value = $ this ->cleanup ($ value );
60
+ $ this ->lines = explode ("\n" , $ value );
61
61
62
62
if (function_exists ('mb_internal_encoding ' ) && ((int ) ini_get ('mbstring.func_overload ' )) & 2 ) {
63
63
$ mbEncoding = mb_internal_encoding ();
@@ -197,9 +197,8 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
197
197
throw new ParseException ('Multiple documents are not supported. ' );
198
198
}
199
199
200
- // 1-liner optionally followed by newline
201
- $ lineCount = count ($ this ->lines );
202
- if (1 === $ lineCount || (2 === $ lineCount && empty ($ this ->lines [1 ]))) {
200
+ // 1-liner optionally followed by newline(s)
201
+ if ($ this ->lines [0 ] === trim ($ value )) {
203
202
try {
204
203
$ value = Inline::parse ($ this ->lines [0 ], $ exceptionOnInvalidType , $ objectSupport , $ this ->refs );
205
204
} catch (ParseException $ e ) {
0 commit comments