Skip to content
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

Yaml: Escaping goes wrong somewhere #11789

Closed
Jille opened this issue Aug 28, 2014 · 6 comments
Closed

Yaml: Escaping goes wrong somewhere #11789

Jille opened this issue Aug 28, 2014 · 6 comments
Labels

Comments

@Jille
Copy link

Jille commented Aug 28, 2014

  $data = "\ttest\\n";
  $yamlstr = \Symfony\Component\Yaml\Yaml::dump($data);
  $parsed = \Symfony\Component\Yaml\Yaml::parse($yamlstr);
  var_dump($data, $yamlstr, $parsed);
  assert($data === $parsed);
string(7) " test\n"
string(10) ""\ttest\n""
string(6) " test
"
Assertion failed: $data === $parsed

I've added it to the test-framework with bdee3e4. I don't have phpUnit installed so I haven't tried them. Could you please check once again I didn't make any mistakes in it?

@stof
Copy link
Member

stof commented Aug 28, 2014

hmm, looks like the \ is not escaped properly in the double-quoted strings

@stof stof added the Yaml label Aug 28, 2014
@xabbuh
Copy link
Member

xabbuh commented Aug 28, 2014

Hm, this seems to be done on purpose (see this test). Though I'm not sure that this is correct.

@stof
Copy link
Member

stof commented Aug 28, 2014

nope, in this test, the original string does not contain a backslash. it contains CRLF (i.e. \r\n in PHP double-quoted strings), which are dumped as \r\n in YAML (which is available on the left in the array, in a single-quoted PHP string)

@xabbuh
Copy link
Member

xabbuh commented Aug 29, 2014

@stof Thanks, you're right. I didn't know that YAML supports them and I didn't look into the specs. :( So, if I'm not wrong, the backslash before the "n" needs to be properly escaped by the dump() call, right?

@stof
Copy link
Member

stof commented Aug 29, 2014

not in the test you linked. But in the example reported in the issue, yes. All \ should be escaped in double-quoted strings, which seems to be broken currently

@xabbuh
Copy link
Member

xabbuh commented Aug 29, 2014

@stof Thank you. I'll try to fix it.

fabpot added a commit that referenced this issue Sep 5, 2014
…abbuh)

This PR was merged into the 2.3 branch.

Discussion
----------

[YAML] properly mask escape sequences in quoted strings

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #11789
| License       | MIT
| Doc PR        |

Commits
-------

a7d0cf2 properly mask escape sequences in quoted strings
@fabpot fabpot closed this as completed Sep 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants