API: Avoid number/string confusion in YAML
authorRoan Kattouw <catrope@users.mediawiki.org>
Thu, 13 Mar 2008 20:59:29 +0000 (20:59 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Thu, 13 Mar 2008 20:59:29 +0000 (20:59 +0000)
includes/api/ApiFormatYaml_spyc.php

index b2973b8..a6cd26d 100644 (file)
     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)));
+       
     }
   
     /**
      */ 
     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);