[Fusionforge-commits] FusionForge branch master updated. v6.0.5-1918-g29b7862

Thorsten Glaser mirabilos at libremir.placard.fr.eu.org
Thu Jun 8 18:01:45 CEST 2017


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "FusionForge".

The branch, master has been updated
       via  29b7862e2e548cf6e757320c217ac51e082e0cb2 (commit)
      from  5daeca64c0d74553b373517890ece505ca187004 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://scm.fusionforge.org/anonscm/gitweb/?p=fusionforge/fusionforge.git;a=commitdiff;h=29b7862e2e548cf6e757320c217ac51e082e0cb2

commit 29b7862e2e548cf6e757320c217ac51e082e0cb2
Author: mirabilos <t.glaser at tarent.de>
Date:   Thu Jun 8 18:01:13 2017 +0200

    update miniJSON from hello-php-world (= 16)
    
    * prefer strval($x) over (''.$x) and ((string)$x)
      => feedback welcome
    * return empty JSONArray and JSONObject as [] and {}
      without extra whitespace in between, following ECMA 262
    * make minijson.php executable, add a shebang
      (makes it directly runnable as pretty-printer)
    
    cf. https://evolvis.org/plugins/scmgit/cgi-bin/gitweb.cgi?p=shellsnippets/hello-php-world.git;a=summary

diff --git a/src/common/include/minijson.php b/src/common/include/minijson.php
old mode 100644
new mode 100755
index 6b96cbc..a5a87d5
--- a/src/common/include/minijson.php
+++ b/src/common/include/minijson.php
@@ -1,3 +1,4 @@
+#!/usr/bin/env php
 <?php
 if (count(get_included_files()) === 1) define('__main__', __FILE__);
 /**
@@ -69,10 +70,10 @@ function minijson_encode_internal($x, $ri, $depth, $truncsz, $dumprsrc) {
 		return 'false';
 	if (is_int($x)) {
 		$y = (int)$x;
-		$z = (string)$y;
+		$z = strval($y);
 		if ($x == $z)
 			return $z;
-		$x = (string)$x;
+		$x = strval($x);
 	}
 	if (is_float($x)) {
 		$rs = sprintf('%.14e', $x);
@@ -99,7 +100,7 @@ function minijson_encode_internal($x, $ri, $depth, $truncsz, $dumprsrc) {
 		/*
 		 * A bit unbelievable: not only does mb_check_encoding
 		 * not exist from the start, but also does it not check
-		 * reliably – so converting forth and back is the way
+		 * reliably — so converting forth and back is the way
 		 * they recommend… also, JSON is not binary-safe either…
 		 */
 		$isunicode = false;
@@ -157,12 +158,15 @@ function minijson_encode_internal($x, $ri, $depth, $truncsz, $dumprsrc) {
 	}
 	if (is_array($x)) {
 		$k = array_keys($x);
+		if (!$k) {
+			return '[]';
+		}
 
 		$isnum = true;
 		foreach ($k as $v) {
 			if (is_int($v)) {
 				$y = (int)$v;
-				$z = (string)$y;
+				$z = strval($y);
 				if ($v != $z) {
 					$isnum = false;
 					break;
@@ -226,7 +230,7 @@ function minijson_encode_internal($x, $ri, $depth, $truncsz, $dumprsrc) {
 				$rs .= ",\n";
 			if ($si !== false)
 				$rs .= $si;
-			$rs .= minijson_encode_internal((string)$v, false,
+			$rs .= minijson_encode_internal(strval($v), false,
 			    $depth, $truncsz, $dumprsrc);
 			if ($ri === false)
 				$rs .= ':';
@@ -249,6 +253,9 @@ function minijson_encode_internal($x, $ri, $depth, $truncsz, $dumprsrc) {
 			$k[$v] = preg_replace('/^\0([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*|\*)\0(.)/',
 			    '\\\\$1\\\\$2', $v);
 		}
+		if (!$k) {
+			return '{}';
+		}
 		$si = $ri === false ? false : $ri . '  ';
 		$first = true;
 		$rs = '{';
@@ -281,7 +288,7 @@ function minijson_encode_internal($x, $ri, $depth, $truncsz, $dumprsrc) {
 
 	/* http://de2.php.net/manual/en/function.is-resource.php#103942 */
 	if ($dumprsrc && !is_null($rsrctype = @get_resource_type($x))) {
-		$k = ''.$rsrctype;
+		$k = strval($rsrctype);
 		$rs = '{';
 		if ($ri !== false)
 			$rs .= "\n" . $ri . '  ';
@@ -297,7 +304,7 @@ function minijson_encode_internal($x, $ri, $depth, $truncsz, $dumprsrc) {
 	}
 
 	/* treat everything else as array or string */
-	return minijson_encode_internal(is_scalar($x) ? (string)$x : (array)$x,
+	return minijson_encode_internal(is_scalar($x) ? strval($x) : (array)$x,
 	    $ri, $depth, $truncsz, $dumprsrc);
 }
 
@@ -703,7 +710,7 @@ function minijson_decode_number(&$j, &$p, &$ov) {
 		/* no fractional part, no exponent */
 
 		$v = (int)$s;
-		if ((string)$v == $s) {
+		if (strval($v) == $s) {
 			$ov = $v;
 			return true;
 		}
@@ -747,7 +754,7 @@ if (defined('__main__') && constant('__main__') === __FILE__) {
 				$depth = array_shift($argv);
 				if (!preg_match('/^[1-9][0-9]*$/', $depth))
 					usage();
-				if ((string)(int)$depth !== $depth)
+				if (strval((int)$depth) !== $depth)
 					usage();
 				$depth = (int)$depth;
 				break;
@@ -763,7 +770,7 @@ if (defined('__main__') && constant('__main__') === __FILE__) {
 				$truncsz = array_shift($argv);
 				if (!preg_match('/^[1-9][0-9]*$/', $truncsz))
 					usage();
-				if ((string)(int)$truncsz !== $truncsz)
+				if (strval((int)$truncsz) !== $truncsz)
 					usage();
 				$truncsz = (int)$truncsz;
 				break;
diff --git a/tests/unit/common/minijsonTest.php b/tests/unit/common/minijsonTest.php
index 3d06941..e6194a6 100644
--- a/tests/unit/common/minijsonTest.php
+++ b/tests/unit/common/minijsonTest.php
@@ -2,31 +2,32 @@
 /*-
  * Small test for the minijson encoder/decoder routines
  *
- * Copyright © 2011, 2012
- *	Thorsten Glaser <mirabilos at evolvis.org>
- * All rights reserved.
+ * Copyright © 2011, 2012, 2017
+ *	mirabilos <t.glaser at tarent.de>
+ * Contributions by:
+ *	Roland Mas <lolando at debian.org>
+ *	Alain Peyrat <aljeux at free.fr>
  *
- * This file is part of FusionForge. FusionForge is free software;
- * you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the Licence, or (at your option)
- * any later version.
+ * Provided that these terms and disclaimer and all copyright notices
+ * are retained or reproduced in an accompanying document, permission
+ * is granted to deal in this work without restriction, including un‐
+ * limited rights to use, publicly perform, distribute, sell, modify,
+ * merge, give away, or sublicence.
  *
- * FusionForge is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with FusionForge; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
+ * the utmost extent permitted by applicable law, neither express nor
+ * implied; without malicious intent or gross negligence. In no event
+ * may a licensor, author or contributor be held liable for indirect,
+ * direct, other damage, loss, or other issues arising in any way out
+ * of dealing in the work, even if advised of the possibility of such
+ * damage or existence of a defect, except proven that it results out
+ * of said person’s immediate fault when using the work as intended.
  */
 
-require_once 'PHPUnit/Framework/TestCase.php';
-require_once dirname(__FILE__) . '/../../../src/common/include/minijson.php';
+require_once('PHPUnit/Framework/TestCase.php');
+require_once(dirname(__FILE__) . '/../../../src/common/include/minijson.php');
 
-class Minijson_Tests extends PHPUnit_Framework_TestCase
-{
+class Minijson_Tests extends PHPUnit_Framework_TestCase {
 	/****************************************************************/
 	/* $s_orig [parse] print_r->$s_printr [encode] $s_ecompact or $s_epadded */
 	/* $s_e* [decode] print_r ->$s_printrs (due to Object key sorting) */
@@ -302,12 +303,8 @@ class Minijson_Tests extends PHPUnit_Framework_TestCase
       "array with 1 element"
     ]
   },
-  [
-
-  ],
-  [
-
-  ],
+  [],
+  [],
   -42,
   true,
   false,
@@ -330,9 +327,7 @@ class Minijson_Tests extends PHPUnit_Framework_TestCase
     "E": 1.23456789E+34,
     "address": "50 St. James Street",
     "alpha": "abcdefghijklmnopqrstuvwyz",
-    "array": [
-
-    ],
+    "array": [],
     "backslash": "\\\\",
     "comment": "// /* <!-- --",
     "compact": [
@@ -352,9 +347,7 @@ class Minijson_Tests extends PHPUnit_Framework_TestCase
     "integer": 1234567890,
     "jsontext": "{\\"object with 1 member\\":[\\"array with 1 element\\"]}",
     "null": null,
-    "object": [
-
-    ],
+    "object": [],
     "one": 1,
     "quote": "\\"",
     "quotes": "" \\" %22 0x22 034 &#x22;",
@@ -381,8 +374,7 @@ class Minijson_Tests extends PHPUnit_Framework_TestCase
 
 /****************************************************************/
 
-	public function testMiniJson()
-	{
+	public function testMiniJson() {
 		$parsed = 'bla';
 		$presult = minijson_decode($this->s_orig, $parsed);
 		$this->assertTrue($presult);

-----------------------------------------------------------------------

Summary of changes:
 src/common/include/minijson.php    | 27 ++++++++++-------
 tests/unit/common/minijsonTest.php | 60 +++++++++++++++++---------------------
 2 files changed, 43 insertions(+), 44 deletions(-)
 mode change 100644 => 100755 src/common/include/minijson.php


hooks/post-receive
-- 
FusionForge



More information about the Fusionforge-commits mailing list