Skip to content

[Yaml] Fix error handling on ini file parsing #22105

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

Merged
merged 1 commit into from
Mar 22, 2017

Conversation

chalasr
Copy link
Member

@chalasr chalasr commented Mar 22, 2017

Q A
Branch? master
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR n/a

Should make travis green again on master.
/cc @xabbuh

Copy link
Member

@xabbuh xabbuh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@javiereguiluz
Copy link
Member

👍

@xabbuh
Copy link
Member

xabbuh commented Mar 22, 2017

Thank you @chalasr.

@xabbuh xabbuh merged commit 71cec82 into symfony:master Mar 22, 2017
xabbuh added a commit that referenced this pull request Mar 22, 2017
This PR was merged into the 3.3-dev branch.

Discussion
----------

[Yaml] Fix error handling on ini file parsing

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Should make travis green again on master.
/cc @xabbuh

Commits
-------

71cec82 [Yaml] Fix error handling in parser
@chalasr chalasr deleted the yaml-parse-fix branch March 22, 2017 12:03
@GuilhemN
Copy link
Contributor

This part of the code supports things that shouldn't be.
e.g:

"foo"
bar

is not valid.

bar
"foo"

is valid but should be parsed as "bar\n\"foo\"" and not "bar\nfoo.

This could be fixed by updating some things:

  • first, trim the empty lines at the beginning of the value
  • if the value begins with *, {, [, ] or } throw an exception (correct reference and correct inline mappings/sequences are parsed earlier)
  • (if the value begins with &, trim it? or throw an exception as it does not really make sense?)
  • if the value begins with !, trim the tag and process the value without it
  • if the value begins with ' or ", pass the entire value to Inline::parse() but trim the last lines if they are empty.
  • otherwise, if the value is not special, threat the value "manually":
foreach ($lines as $line) {
    if ($this->preg_match('/[ \t]+#/', $line, $match, PREG_OFFSET_CAPTURE)) {
        $line = substr($line, 0, $match[0][1]);
    }

    if ('' === trim($line)) {
        $value .= "\n";
        $previousLineWasNewline = true;
    } elseif ($previousLineWasNewline) {
        $value .= trim($line);
        $previousLineWasNewline = false;
    } else {
        $value .= ' '.trim($line);
        $previousLineWasNewline = false;
    }
}

fabpot added a commit that referenced this pull request May 24, 2017
This PR was merged into the 3.3 branch.

Discussion
----------

[Yaml] fix multiline block handling

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #21114, #22105 (comment)
| License       | MIT
| Doc PR        |

Commits
-------

a2079d6 [Yaml] fix multiline block handling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants