Skip to content

Commit

Permalink
update Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jul 21, 2017
1 parent 99bf694 commit d2ac34a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Changes
@@ -1,5 +1,7 @@

7.37 2017-07-19
7.37 2017-07-21
- Added slugify method to Mojo::ByteStream. (Grinnz)
- Added slugify function to Mojo::Util. (Grinnz)
- Fixed bugs in Mojo::IOLoop and Mojo::Reactor::Poll that would prevent a
reset from clearing events.

Expand Down
6 changes: 4 additions & 2 deletions lib/Mojo/Util.pm
Expand Up @@ -251,17 +251,19 @@ sub secure_compare {

sub slugify {
my ($value, $allow_unicode) = @_;

if ($allow_unicode) {

# force unicode semantics by upgrading string
# Force unicode semantics by upgrading string
utf8::upgrade($value = Unicode::Normalize::NFKC($value));
$value =~ s/[^\w\s-]+//g;
}
else {
$value = Unicode::Normalize::NFKD($value);
$value =~ s/[^a-zA-Z0-9_\p{PosixSpace}-]+//g; # ascii word/space/dash chars
$value =~ s/[^a-zA-Z0-9_\p{PosixSpace}-]+//g;
}
(my $new = lc trim($value)) =~ s/[-\s]+/-/g;

return $new;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Plugin/DefaultHelpers.pm
Expand Up @@ -217,7 +217,7 @@ Alias for L<Mojolicious::Controller/"app">.
=head2 b
%= b('test 123')->b64_encode
%= b('Joel is a slug')->slugify
Turn string into a L<Mojo::ByteStream> object.
Expand Down
4 changes: 2 additions & 2 deletions t/mojo/bytestream.t
Expand Up @@ -136,9 +136,9 @@ is $buffer, "test\n123\n\"123\"\n", 'right output';
is b("\t\b\r\n\f")->term_escape, "\\x09\\x08\\x0d\n\\x0c", 'right result';

# slugify
is b("Un \x{e9}l\x{e9}phant \x{e0} l'or\x{e9}e du bois")->slugify,
is b("Un \x{e9}l\x{e9}phant \x{e0} l'or\x{e9}e du bois")->slugify->to_string,
'un-elephant-a-loree-du-bois', 'right result';
is b("Un \x{e9}l\x{e9}phant \x{e0} l'or\x{e9}e du bois")->slugify(1),
is b("Un \x{e9}l\x{e9}phant \x{e0} l'or\x{e9}e du bois")->slugify(1)->to_string,
"un-\x{e9}l\x{e9}phant-\x{e0}-lor\x{e9}e-du-bois", 'right result';

done_testing();

0 comments on commit d2ac34a

Please sign in to comment.