From: Roan Kattouw Date: Thu, 13 Mar 2008 16:44:05 +0000 (+0000) Subject: (bug 12120) Unescaped quote in YAML output X-Git-Tag: 1.31.0-rc.0~49137 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22suivi_revisions%22%29%20.%20%22?a=commitdiff_plain;h=e2fa08555c71171d8cdc2ac024dcddd9e3f844df;p=lhc%2Fweb%2Fwiklou.git (bug 12120) Unescaped quote in YAML output --- diff --git a/includes/api/ApiFormatYaml_spyc.php b/includes/api/ApiFormatYaml_spyc.php index b3ccff0fef..b2973b8c4f 100644 --- a/includes/api/ApiFormatYaml_spyc.php +++ b/includes/api/ApiFormatYaml_spyc.php @@ -385,6 +385,18 @@ return false; } } + + /** + * Find out whether a string needs to be output as a literal rather than in plain style. + * Added by Roan Kattouw 13-03-2008 + * @param $value The string to check + * @return bool + */ + function _needLiteral($value) { + # Check whether the string contains # or : or begins with any of: + # [ - ? , [ ] { } ! * & | > ' " % @ ` ] + return (bool)(preg_match("/[#:]/", $value) || preg_match("/^[-?,[\]{}!*&|>'\"%@`]/", $value)); + } /** * Returns YAML from a key and a value @@ -396,7 +408,7 @@ */ function _dumpNode($key,$value,$indent) { // do some folding here, for blocks - if (strpos($value,"\n")) { + if (strpos($value,"\n") || $this->_needLiteral($value)) { $value = $this->_doLiteralBlock($value,$indent); } else { $value = $this->_doFolding($value,$indent);