Skip to content

Commit

Permalink
improved whitespace trimming in Mojo::DOM
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jun 17, 2011
1 parent 314fec1 commit 0d69830
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Changes
Expand Up @@ -4,11 +4,14 @@ This file documents the revision history for Perl extension Mojolicious.
- Added EXPERIMENTAL self-restarting Morbo development web server and
removed old "--reload" support since there have been too many
negative side effects.
This also improves overall performance by about 5-10% and reduces
memory usage by about 10%.
- Added EXPERIMENTAL application mount plugin.
- Updated prettify.js to version 1-Jun-2011.
- Updated WebSocket diagnostics test in Mojo::HelloWorld for latest
Firefox Aurora.
- Improved inline template and static file performance.
- Improved whitespace trimming in Mojo::DOM. (sri, DaTa)
- Improved documentation.
- Improved tests.
- Fixed Morbo file discovery bug. (crab)
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/DOM.pm
Expand Up @@ -1280,7 +1280,7 @@ sub _trim {
$text =~ s/\s*\n+\s*/\ /g;

# Add leading whitespace
$text = " $text" if $ws;
$text = " $text" if $ws && $text =~ /^[^\,\.\;]/;

return $text;
}
Expand Down
17 changes: 16 additions & 1 deletion t/mojo/dom.t
Expand Up @@ -5,7 +5,7 @@ use warnings;

use utf8;

use Test::More tests => 591;
use Test::More tests => 595;

# "Homer gave me a kidney: it wasn't his, I didn't need it,
# and it came postage due- but I appreciated the gesture!"
Expand Down Expand Up @@ -1309,6 +1309,21 @@ is $dom->find('body > ul > li > p')->[2]->text, '', 'no text';
is $dom->find('body > ul > li')->[2]->all_text, 'Test 3 2 1', 'right text';
is $dom->find('body > ul > li > p')->[2]->all_text, '', 'no text';

# Advanced whitespace trimming
$dom = Mojo::DOM->new->parse(<<EOF);
<html>
<head>
<title>Real World!</title>
<body>
<div>foo <strong>bar</strong>.</div>
<div>foo<strong>, bar</strong>baz<strong>; yada</strong>.</div>
EOF
is $dom->find('html > head > title')->[0]->text, 'Real World!', 'right text';
is $dom->find('body > div')->[0]->all_text, 'foo bar.', 'right text';
is $dom->find('body > div')->[1]->all_text, 'foo, bar baz; yada.',
'right text';
is $dom->find('body > div')->[1]->text, 'foo baz.', 'right text';

# Real world JavaScript and CSS
$dom = Mojo::DOM->new->parse(<<EOF);
<html>
Expand Down

0 comments on commit 0d69830

Please sign in to comment.