Permalink
Browse files

should use \\\\ instead of \\ when passing regexp as strings

  • Loading branch information...
1 parent 9b75f41 commit 825587771f7c4cc55e8e35d63c6043d79ebb8b4a @kazuho committed Sep 23, 2010
Showing with 6 additions and 6 deletions.
  1. +3 −3 lib/String/Filter.pm
  2. +3 −3 t/00base.t
View
@@ -77,15 +77,15 @@ String::Filter - a regexp-based string filter
# (handles url, @user, #hash)
my $sf = String::Filter->new(
rules => [
- 'http://[A-Za-z0-9_\-\~\.\%\?\#\@/]+' => sub {
+ 'http://[A-Za-z0-9_\\-\\~\\.\\%\\?\\#\\@/]+' => sub {
my $url = shift;
sprintf(
'<a href="%s">%s</a>',
encode_entities($url),
encode_entities($url),
);
},
- '(?:^|\s)\@[A-Za-z0-9_]+' => sub {
+ '(?:^|\\s)\\@[A-Za-z0-9_]+' => sub {
$_[0] =~ /^(.*?\@)(.*)$/;
my ($prefix, $user) = ($1, $2);
sprintf(
@@ -95,7 +95,7 @@ String::Filter - a regexp-based string filter
encode_entities($user),
);
},
- '(?:^|\s)#[A-Za-z0-9_]+' => sub {
+ '(?:^|\\s)#[A-Za-z0-9_]+' => sub {
$_[0] =~ /^(.?)(#.*)$/;
my ($prefix, $hashtag) = ($1, $2);
sprintf(
View
@@ -9,16 +9,16 @@ use_ok('String::Filter');
my $sf = String::Filter->new(
rules => [
- 'http://[A-Za-z0-9_\-\~\.\%\?\#\@/]+' => sub {
+ 'http://[A-Za-z0-9_\\-\\~\\.\\%\\?\\#\\@/]+' => sub {
my $url = shift;
qq{<a href="@{[encode_entities($url)]}">@{[encode_entities($url)]}</a>};
},
- '(?:^|\s)\@[A-Za-z0-9_]+' => sub {
+ '(?:^|\\s)\\@[A-Za-z0-9_]+' => sub {
$_[0] =~ /^(.*?\@)(.*)$/;
my ($prefix, $user) = ($1, $2);
qq{$prefix<a href="http://twitter.com/@{[encode_entities($user)]}">$user</a>};
},
- '(?:^|\s)#[A-Za-z0-9_]+' => sub {
+ '(?:^|\\s)#[A-Za-z0-9_]+' => sub {
$_[0] =~ /^(.?)(#.*)$/;
my ($prefix, $hashtag) = ($1, $2);
qq{$prefix<a href="http://twitter.com/search?q=@{[encode_entities(uri_escape($hashtag))]}"><b>@{[encode_entities($hashtag)]}</b></a>};

0 comments on commit 8255877

Please sign in to comment.