Permalink
Browse files

Fixed bug in n_words, or instead improved it to properly process elis…

…pses
  • Loading branch information...
1 parent c1fc129 commit a5c7df4a3a4b0cca8b4d36cd8647442478527716 Byrne Reese committed Aug 25, 2011
Showing with 18 additions and 2 deletions.
  1. +3 −1 plugins/ExtraTags/config.yaml
  2. +15 −1 plugins/ExtraTags/lib/ExtraTags/Plugin.pm
View
4 plugins/ExtraTags/config.yaml
@@ -3,7 +3,7 @@ key: Extra Tags
description: A collection of extra template tags that might be helpful.
author_name: Byrne Reese, Endevver LLC
author_link: http://www.endevver.com/
-version: 1.15
+version: 1.17
tags:
block:
@@ -34,3 +34,5 @@ tags:
handler: $ExtraTags::ExtraTags::Plugin::mod_nice_size
n_words:
handler: $ExtraTags::ExtraTags::Plugin::mod_n_words
+ encode_json:
+ handler: $ExtraTags::ExtraTags::Plugin::mod_encode_json
View
16 plugins/ExtraTags/lib/ExtraTags/Plugin.pm
@@ -206,7 +206,7 @@ sub mod_n_words {
my ($str, $val, $ctx) = @_;
return '' unless defined $str;
my $elip;
- ($val,$elip) = ($val =~ /^(\d+)(\.\.\.)?$/);
+ ($val,$elip) = ($val =~ /^(\d+)(\.\.\.?)?$/);
$str = remove_html($str) || '';
my @words = split(/\s+/, $str);
my $max = @words > $val ? $val : @words;
@@ -632,4 +632,18 @@ sub tag_search_to {
return $upper;
}
+sub mod_encode_json {
+ my ($str, $val, $ctx) = @_;
+ return '' unless defined $str;
+ $str =~ s!\\!\\\\!g; # \
+ $str =~ s!\/!\\\/!g; # /
+ $str =~ s!"!\\"!g; # "
+ $str =~ s!\f!\\f!g; # \f
+ $str =~ s!\n!\\n!g; # \n
+ $str =~ s!\r!\\r!g; # \r
+ $str =~ s!\t!\\t!g; # \t
+ $str =~ s!\0!\\0!g;
+ $str;
+}
+
1;

0 comments on commit a5c7df4

Please sign in to comment.