X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;ds=sidebyside;f=lib%2FCGI%2FEx%2FJSONDump.pm;h=c08f496c98c2a7eb4e34229c6b9a26a0b8b47590;hb=refs%2Ftags%2Fv2.24;hp=03ddce970d94e995e67ece8e7d3eb15fa5a66877;hpb=d0287461de3f9b5c49ce02b22957022bdc5e87d8;p=chaz%2Fp5-CGI-Ex
diff --git a/lib/CGI/Ex/JSONDump.pm b/lib/CGI/Ex/JSONDump.pm
index 03ddce9..c08f496 100644
--- a/lib/CGI/Ex/JSONDump.pm
+++ b/lib/CGI/Ex/JSONDump.pm
@@ -17,7 +17,7 @@ use strict;
use base qw(Exporter);
BEGIN {
- $VERSION = '2.07';
+ $VERSION = '2.24';
@EXPORT = qw(JSONDump);
@EXPORT_OK = @EXPORT;
@@ -103,7 +103,7 @@ sub js_escape {
return 'null' if ! defined $str;
### allow things that look like numbers to show up as numbers (and those that aren't quite to not)
- return $str if $str =~ /^ -? (?: [0-9]{0,13} \. \d* [1-9] | [1-9][0-9]{0,12}) $/x;
+ return $str if $str =~ /^ -? (?: [1-9][0-9]{0,12} | 0) (?: \. \d* [1-9])? $/x;
my $quote = $self->{'single_quote'} ? "'" : '"';
@@ -117,7 +117,8 @@ sub js_escape {
utf8::decode($str) if $self->{'utf8'} && &utf8::decode;
### escape and tags in the text
- $str =~ s{(? (?: htm | scrip | !-) | --(?=>) )}{$1$quote+$quote}gx;
+ $str =~ s{(? (?: htm | scrip | !-) | --(?=>) )}{$1$quote+$quote}gx
+ if ! $self->{'no_tag_splitting'};
### add nice newlines (unless pretty is off)
if ($self->{'str_nl'} && length($str) > 80) {
@@ -359,10 +360,39 @@ greater than 80 characters. Default is "\n" (if pretty is true).
If the string is less than 80 characters, or if str_nl is set to "", then the escaped
string will be contained on a single line. Setting pretty to 0 effectively sets str_nl equal to "".
+=item no_tag_splitting
+
+Default off. If JSON is embedded in an HTML document and the JSON contains C<< >>,
+C<< >>, C<< >>, C<< >> tags, they are
+split apart with a quote, a +, and a quote. This allows the embedded tags to not affect
+the currently playing JavaScript.
+
+However, if the JSON that is output is intended for deserialization by another non-javascript-engine
+JSON parser, this splitting behavior may cause errors when the JSON is imported. To avoid the splitting
+behavior in these cases you can use the no_tag_splitting flag to turn off the behavior.
+
+ JSONDump("");
+
+ Would print
+
+ ""
+
+ With the flag
+
+ JSONDump("", {no_tag_splitting => 1});
+
+ Would print
+
+ ""
+
=back
+=head1 LICENSE
+
+This module may distributed under the same terms as Perl itself.
+
=head1 AUTHORS
-Paul Seamons
+Paul Seamons
=cut