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

Problems with string values that contain dollar sign followed by a number #72

Open
kuntur-studio opened this issue Mar 12, 2018 · 1 comment

Comments

@kuntur-studio
Copy link

Well, I was trying to store a hash of a password on a yaml file and the value retrieved by spyc had some missing characters.
Looking closely I found that the missings were $1, $10 and that kind of combinations, then making some tracing I get to the line 780 and found this:
$explode[$key] = preg_replace('/YAMLString/',$saved_strings[$stringi],$value, 1);
So preg_replace thinks that those are backreferences and tries to do some replacing...
I think, that the same will be happening on other places too.

To solve it look at:
http://php.net/manual/en/function.preg-replace.php#106263

@kuntur-studio
Copy link
Author

preg_quote will not work for quoting the replacement string, it is intended to work with patterns.
So as written here:
https://www.sitepoint.com/community/t/how-to-escape-replacement-string-for-preg-replace/5769/12

I've escaped the replacement string using this:
$explode[$key] = preg_replace('/YAMLString/', strtr($saved_strings[$stringi], array('\\' => '\\\\', '$' => '\$')), $value, 1);

Tested and working!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant