From 6e2a43045f6f98c4fabf5a3358c2bdfdda2d6688 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 19 Jan 2011 12:35:17 +0000 Subject: =?UTF-8?q?=E2=80=A2=20fixed=20issue=20while=20updating=20Default?= =?UTF-8?q?=20Bundles=20for=20key=20equivalent=20=E2=80=A2=20improved=20JS?= =?UTF-8?q?ON=20Bundle=20commands=20-=20got=20rid=20of=20trailing=20whites?= =?UTF-8?q?paces=20inside=20data=20and=20as=20JSON=20object=20-=20added=20?= =?UTF-8?q?error=20handling=20for=20serialization=20a=20JSON=20object=20to?= =?UTF-8?q?=20suppress=20inserting=20of=20"null"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Default Bundles/CopyAsJSON.spBundle/command.plist | 7 +++++-- .../Default Bundles/Toggle JSON Format.spBundle/command.plist | 10 +++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'SharedSupport') diff --git a/SharedSupport/Default Bundles/CopyAsJSON.spBundle/command.plist b/SharedSupport/Default Bundles/CopyAsJSON.spBundle/command.plist index 86bf998a..f4f1ecd9 100644 --- a/SharedSupport/Default Bundles/CopyAsJSON.spBundle/command.plist +++ b/SharedSupport/Default Bundles/CopyAsJSON.spBundle/command.plist @@ -64,8 +64,11 @@ while($rowData) { print "null"; } elsif($meta[$i]->[1] eq "integer" || $meta[$i]->[1] eq "float") { - print "$cellData"; + chomp($cellData); + $d = $cellData+0; + print "$d"; } else { + chomp($cellData); print "\"$cellData\""; } @@ -91,7 +94,7 @@ while($rowData) { print "\n"; } -print "\t]\n}\n"; +print "\t]\n}"; ' | __CF_USER_TEXT_ENCODING=$UID:0x8000100:0x8000100 pbcopy contact diff --git a/SharedSupport/Default Bundles/Toggle JSON Format.spBundle/command.plist b/SharedSupport/Default Bundles/Toggle JSON Format.spBundle/command.plist index 6476d86b..39555369 100644 --- a/SharedSupport/Default Bundles/Toggle JSON Format.spBundle/command.plist +++ b/SharedSupport/Default Bundles/Toggle JSON Format.spBundle/command.plist @@ -9,10 +9,10 @@ command DATA=$(cat) -FORMAT=$(echo "$DATA" | head -n 1 | perl -e '$l=<>;print "1" if($l=~m/^\s*\{\s*$/)') +FORMAT=$(echo "$DATA" | head -n 1 | perl -e '$l=<>;if($l=~m/^\s*\{\s*$/) {print "1";} else {print "2";}') # if FORMAT == 1 then serialize JSON data otherwise pretty print them -if [ "$FORMAT" == 1 ]; then +if [ "$FORMAT" -eq "1" ]; then DATA=$(echo "$DATA" | php -r ' $jsonData = ""; @@ -20,6 +20,10 @@ if [ "$FORMAT" == 1 ]; then while($d = fgets($inputStream)) { $jsonData .= $d; } print json_encode(json_decode($jsonData)); ') + if [ "$DATA" == "null" ]; then + echo "<font>An error occured while serializing JSON data!</font>" + exit $SP_BUNDLE_EXIT_SHOW_AS_HTML_TOOLTIP + fi else @@ -30,7 +34,7 @@ fi # if there's a need to preserve Unicode characters remove the first to characters of the following line # DATA=$(echo "$DATA" | perl -Xpe 'binmode STDIN,":utf8";binmode STDOUT,":utf8";s/\\u([0-9A-F]{4})/chr(hex($1))/ieg') -echo "$DATA" +printf "%b" "$DATA" contact znvy@ovovxb.qr description -- cgit v1.2.3