r62102 - in /branches/upstream/libyaml-syck-perl/current: Changes META.yml lib/JSON/Syck.pm lib/YAML/Syck.pm perl_syck.h syck_.c t/2-scalars.t t/json-numbers.t

ansgar-guest at users.alioth.debian.org ansgar-guest at users.alioth.debian.org
Sat Aug 28 13:26:53 UTC 2010


Author: ansgar-guest
Date: Sat Aug 28 13:26:30 2010
New Revision: 62102

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=62102
Log:
[svn-upgrade] new version libyaml-syck-perl (1.14)

Modified:
    branches/upstream/libyaml-syck-perl/current/Changes
    branches/upstream/libyaml-syck-perl/current/META.yml
    branches/upstream/libyaml-syck-perl/current/lib/JSON/Syck.pm
    branches/upstream/libyaml-syck-perl/current/lib/YAML/Syck.pm
    branches/upstream/libyaml-syck-perl/current/perl_syck.h
    branches/upstream/libyaml-syck-perl/current/syck_.c
    branches/upstream/libyaml-syck-perl/current/t/2-scalars.t
    branches/upstream/libyaml-syck-perl/current/t/json-numbers.t

Modified: branches/upstream/libyaml-syck-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libyaml-syck-perl/current/Changes?rev=62102&op=diff
==============================================================================
--- branches/upstream/libyaml-syck-perl/current/Changes (original)
+++ branches/upstream/libyaml-syck-perl/current/Changes Sat Aug 28 13:26:30 2010
@@ -1,6 +1,15 @@
+[Changes for 1.14 (YAML::Syck 0.37 ) - 2010-08-03]
+* RT RT60771 - Further refactor for JSON. if a number is a valid
+  perl string, quote it. "1" + "1" = "11" in javascript.
+* add YAML tests to make sure HEX and octal preserve their information
+
+[Changes for 1.13 (YAML::Syck 0.36 ) - 2010-08-03]
+* RT RT60771 - quoted negative integer and quoted zeroes.
+  This was breaking JSON since "0" is true in javascript.
+
 [Changes for 1.12 (YAML::Syck 0.35 ) - 2010-08-03]
 * The tie test proved to be very unstable for 5.8 and it's not
-  relevant for tie actually. I'm converting it to a TODO for now.
+  relevant for tie actually. I'm converting it to a TODO for 
 
 [Changes for 1.11 (YAML::Syck 0.35 ) - 2010-08-03]
 * Tests are now stable. releasing 1.11

Modified: branches/upstream/libyaml-syck-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libyaml-syck-perl/current/META.yml?rev=62102&op=diff
==============================================================================
--- branches/upstream/libyaml-syck-perl/current/META.yml (original)
+++ branches/upstream/libyaml-syck-perl/current/META.yml Sat Aug 28 13:26:30 2010
@@ -25,4 +25,4 @@
   homepage: http://search.cpan.org/dist/YAML-Syck
   license: http://opensource.org/licenses/mit-license.php
   repository: http://github.com/avar/YAML-Syck
-version: 1.12
+version: 1.14

Modified: branches/upstream/libyaml-syck-perl/current/lib/JSON/Syck.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libyaml-syck-perl/current/lib/JSON/Syck.pm?rev=62102&op=diff
==============================================================================
--- branches/upstream/libyaml-syck-perl/current/lib/JSON/Syck.pm (original)
+++ branches/upstream/libyaml-syck-perl/current/lib/JSON/Syck.pm Sat Aug 28 13:26:30 2010
@@ -5,7 +5,7 @@
 use YAML::Syck ();
 
 BEGIN {
-    $VERSION    = '0.35';
+    $VERSION    = '0.37';
     @EXPORT_OK  = qw( Load Dump LoadFile DumpFile );
     @ISA        = 'Exporter';
     *Load       = \&YAML::Syck::LoadJSON;

Modified: branches/upstream/libyaml-syck-perl/current/lib/YAML/Syck.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libyaml-syck-perl/current/lib/YAML/Syck.pm?rev=62102&op=diff
==============================================================================
--- branches/upstream/libyaml-syck-perl/current/lib/YAML/Syck.pm (original)
+++ branches/upstream/libyaml-syck-perl/current/lib/YAML/Syck.pm Sat Aug 28 13:26:30 2010
@@ -13,7 +13,7 @@
 use Exporter;
 
 BEGIN {
-    $VERSION = '1.12';
+    $VERSION = '1.14';
     @EXPORT  = qw( Dump Load DumpFile LoadFile );
     @ISA     = qw( Exporter );
 

Modified: branches/upstream/libyaml-syck-perl/current/perl_syck.h
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libyaml-syck-perl/current/perl_syck.h?rev=62102&op=diff
==============================================================================
--- branches/upstream/libyaml-syck-perl/current/perl_syck.h (original)
+++ branches/upstream/libyaml-syck-perl/current/perl_syck.h Sat Aug 28 13:26:30 2010
@@ -982,6 +982,8 @@
         /* emit a string */
         STRLEN len = sv_len(sv);
 
+/* JSON should preserve quotes even on simple integers ("0" is true in javascript) */
+#ifndef YAML_IS_JSON
         if (looks_like_number(sv)) {
         	if(syck_str_is_unquotable_integer(SvPV_nolen(sv), sv_len(sv))) {
         		/* emit an unquoted number only if it's a very basic integer. /^-?[1-9][0-9]*$/ */
@@ -992,7 +994,9 @@
         		syck_emit_scalar(e, OBJOF("str"), SCALAR_QUOTED, 0, 0, 0, SvPV_nolen(sv), len);
         	}
         }
-        else if (len == 0) {
+        else
+#endif
+        	if (len == 0) {
             syck_emit_scalar(e, OBJOF("str"), SCALAR_QUOTED, 0, 0, 0, "", 0);
         }
         else if (IS_UTF8(sv)) {

Modified: branches/upstream/libyaml-syck-perl/current/syck_.c
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libyaml-syck-perl/current/syck_.c?rev=62102&op=diff
==============================================================================
--- branches/upstream/libyaml-syck-perl/current/syck_.c (original)
+++ branches/upstream/libyaml-syck-perl/current/syck_.c Sat Aug 28 13:26:30 2010
@@ -503,19 +503,20 @@
 }
 
 int syck_str_is_unquotable_integer(char* str, long len) {
-	int idx;
-
-	if(!str) return 0; /* Don't parse null strings */
-	if(len < 1) return 0; /* empty strings can't be numbers */
-	if(len > 9) return 0; /* Ints larger than 9 digits (32bit) might not portable. Force a string. */
-
-	if(str[0] == '-' && (len < 2 || str[1] > '9' || str[1] < '1')) return 0;
-	if(str[0] > '9' || str[0] < '1') return 0;
-
-	/* Look for illegal characters */
-	for ( idx = 1; idx < len; idx++ ) {
-		if(!isdigit(str[idx])) return 0;
-	}
-
-	return 1;
-}
+    int idx;
+
+    if(!str) return 0; /* Don't parse null strings */
+    if(len < 1) return 0; /* empty strings can't be numbers */
+    if(len > 9) return 0; /* Ints larger than 9 digits (32bit) might not portable. Force a string. */
+
+    if(str[0] == '0' && len == 1) return 1; /* 0 is unquoted. */
+    if(str[0] == '-') {str++; len --;} /* supress the leading '-' sign if detected for testing purposes only. */
+    if(str[0]  == '0') return 0; /* Octals need to be quoted or you lose data converting them to an integer. This also accidentally blocks -0 which probably needs to be quoted. */
+
+    /* Look for illegal characters */
+    for ( idx = 1; idx < len; idx++ ) {
+        if(!isdigit(str[idx])) return 0;
+    }
+
+    return 1;
+}

Modified: branches/upstream/libyaml-syck-perl/current/t/2-scalars.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libyaml-syck-perl/current/t/2-scalars.t?rev=62102&op=diff
==============================================================================
--- branches/upstream/libyaml-syck-perl/current/t/2-scalars.t (original)
+++ branches/upstream/libyaml-syck-perl/current/t/2-scalars.t Sat Aug 28 13:26:30 2010
@@ -1,4 +1,4 @@
-use t::TestYAML tests => 121;
+use t::TestYAML tests => 134;
 
 ok(YAML::Syck->VERSION);
 
@@ -228,6 +228,19 @@
     roundtrip($_);
 }
 
+# Simple integers dump without quotes
+foreach (1, 2, 3, 0, -1, -2, -3) {
+    is(Dump($_), "--- $_\n", "Dumped version of file is unquoted");
+}
+
+is(Dump('0x10'), "--- 0x10\n",   "hex Dump preserves as string");
+is(Load("--- '0x10'\n"), "0x10", "hex Load preserves as string");
+
+is(Dump('080'), "--- '080'\n",   "oct Dump preserves by quoting");
+is(Load("--- '080'\n"), "080", "oct Load preserves by quoting");
+
+is(Dump('00'), "--- '00'\n",   "00 Dump preserves by quoting");
+is(Load("--- '00'\n"), "00", "00 Load preserves by quoting");
 
 # RT 54780 - double quoted loading style
 

Modified: branches/upstream/libyaml-syck-perl/current/t/json-numbers.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libyaml-syck-perl/current/t/json-numbers.t?rev=62102&op=diff
==============================================================================
--- branches/upstream/libyaml-syck-perl/current/t/json-numbers.t (original)
+++ branches/upstream/libyaml-syck-perl/current/t/json-numbers.t Sat Aug 28 13:26:30 2010
@@ -1,14 +1,14 @@
-use Test::More tests => 10;
+use Test::More tests => 53;
 
 use JSON::Syck qw(Dump);
 
 my @arr1 = sort {$a cmp $b} qw/1 2 54 howdy/;
-is(Dump(\@arr1), '[1,2,54,"howdy"]', "cmp sort doesn't coerce numbers into strings");
+is(Dump(\@arr1), '["1","2","54","howdy"]', "cmp sort causes numbers to coerce into strings and thus be quoted.");
 
 {
     no warnings "numeric";
     my @arr2 = sort {$a <=> $b} qw/1 2 54 howdy/;
-    is(Dump(\@arr2), '["howdy",1,2,54]', "Numeric sort doesn't coerce non-numeric strings into numbers");
+    is(Dump(\@arr2), '["howdy","1","2","54"]', "Numeric sort doesn't coerce non-numeric strings into numbers because they still contain their valid string");
 }
 
 my @arr54 = ("howdy",1,2,54);
@@ -21,5 +21,12 @@
 is(Dump('1,000,000'),    '"1,000,000"', "numbers with commas get quoted.");
 is(Dump('1e+6'),    '"1e+6"', "Scientific notation gets quoted.");
 is(Dump('10e+6'),    '"10e+6"', "Scientific notation gets quoted.");
+is(Dump('0123'),    '"0123"', "Scientific notation gets quoted.");
 
-
+# for simple integers, we need to preserve their string state as perl knows it if possible.
+# JSON overloaded + for string concatenation. This means you get all sorts of wierdness if we try to strip quotes on strings not IVs
+# "0" is true 0 is false. 1 + 1 = 2 but "1" + "1" = "11"
+for(-10..10) { 
+  is(Dump($_),  $_,         '"0" != 0 in JSON. 0 is false "0" is true.');
+  is(Dump("$_"),  "\"$_\"", 'Strigified integer is stringified in JSON');
+}




More information about the Pkg-perl-cvs-commits mailing list