-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Yaml] parse PHP constants in mapping keys #22878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -208,7 +208,7 @@ private function doParse($value, $flags) | |
$this->refs[$isRef] = end($data); | ||
} | ||
} elseif ( | ||
self::preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|(?:![^\s]++\s++)?[^ \'"\[\{!].*?) *\:(\s++(?P<value>.+))?$#u', rtrim($this->currentLine), $values) | ||
self::preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|(?:!?!php/const:)?(?:![^\s]++\s++)?[^ \'"\[\{!].*?) *\:(\s++(?P<value>.+))?$#u', rtrim($this->currentLine), $values) | ||
&& (false === strpos($values['key'], ' #') || in_array($values['key'][0], array('"', "'"))) | ||
) { | ||
if ($context && 'sequence' == $context) { | ||
|
@@ -221,7 +221,14 @@ private function doParse($value, $flags) | |
try { | ||
Inline::$parsedLineNumber = $this->getRealCurrentLineNb(); | ||
$i = 0; | ||
$key = Inline::parseScalar($values['key'], 0, null, $i, !(Yaml::PARSE_KEYS_AS_STRINGS & $flags)); | ||
$evaluateKey = !(Yaml::PARSE_KEYS_AS_STRINGS & $flags); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really don't get why we would ever want to use this flag, this is like saying "I don't want to respect the spec", don't you think we should just deprecate it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need this to deprecate the previous behaviour. Otherwise we have no smooth upgrade path in 3.4. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #21774 introduced a small bc break anyway and this only allows people to go back to the old behavior by using this flag, right? |
||
|
||
// constants in key will be evaluated anyway | ||
if (isset($values['key'][0]) && '!' === $values['key'][0] && Yaml::PARSE_CONSTANT & $flags) { | ||
$evaluateKey = true; | ||
} | ||
|
||
$key = Inline::parseScalar($values['key'], 0, null, $i, $evaluateKey); | ||
} catch (ParseException $e) { | ||
$e->setParsedLine($this->getRealCurrentLineNb() + 1); | ||
$e->setSnippet($this->currentLine); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the
!php/const
tag is a bit special as it is separated with a colon from its value instead of a space which is used when parsing other tags