From: Roan Kattouw Date: Thu, 13 Mar 2008 20:59:29 +0000 (+0000) Subject: API: Avoid number/string confusion in YAML X-Git-Tag: 1.31.0-rc.0~49130 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=d42208106081a21fc5ad8fa762c558777c643b52;p=lhc%2Fweb%2Fwiklou.git API: Avoid number/string confusion in YAML --- diff --git a/includes/api/ApiFormatYaml_spyc.php b/includes/api/ApiFormatYaml_spyc.php index b2973b8c4f..a6cd26dc9b 100644 --- a/includes/api/ApiFormatYaml_spyc.php +++ b/includes/api/ApiFormatYaml_spyc.php @@ -395,7 +395,13 @@ function _needLiteral($value) { # Check whether the string contains # or : or begins with any of: # [ - ? , [ ] { } ! * & | > ' " % @ ` ] - return (bool)(preg_match("/[#:]/", $value) || preg_match("/^[-?,[\]{}!*&|>'\"%@`]/", $value)); + # or is a number or contains newlines + return (bool)(gettype($value) == "string" && + (is_numeric($value) || + strpos($value, "\n") || + preg_match("/[#:]/", $value) || + preg_match("/^[-?,[\]{}!*&|>'\"%@`]/", $value))); + } /** @@ -408,7 +414,7 @@ */ function _dumpNode($key,$value,$indent) { // do some folding here, for blocks - if (strpos($value,"\n") || $this->_needLiteral($value)) { + if ($this->_needLiteral($value)) { $value = $this->_doLiteralBlock($value,$indent); } else { $value = $this->_doFolding($value,$indent);