简体   繁体   English

Symfony2 Yaml Dumper单引号转义

[英]Symfony2 Yaml Dumper single quote escaping

I've got some csv translations that are transformed and written into messages.fr.yml with Symfony\\Component\\YamlDumper, and on strings like d'achat it becomes 'd''achat' . 我有一些csv转换,这些转换已使用Symfony \\ Component \\ YamlDumper转换并写入messages.fr.yml,在像d'achat这样的字符串上,它变成了'd'achat'

I've done some debugging and discovered that the string is recognized as the one that needs escaping: 我进行了一些调试,发现该字符串被识别为需要转义的字符串:

preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` ]/x', $value)

and then escaped with the following code: 然后使用以下代码进行转义:

return sprintf("'%s'", str_replace('\'', '\'\'', $value));

I already tried using function addslashes before the debugging, but this escaping is not recognized. 我已经尝试在调试之前使用功能addlashes,但是无法识别这种转义。

So I'd like to know the opinion of the Symfony community: is it a bug or is it a feature? 因此,我想了解Symfony社区的意见:是Bug还是功能? Should I report it and fix or just check my inputs and replace single quotes (') with apostrophe (')? 我应该报告并修复还是仅检查输入内容,并用单引号(')替换单引号(')?

In YAML, a double quote ('' - 2 singles) is how a single ' quote is escaped. 在YAML中,双引号(''-2单打)是如何对单'引号进行转义。

This is not a bug & the double quotes are automatically converted to single quotes by the YAML parser. 这不是错误,并且YAML解析器将双引号自动转换为单引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM