Skip to content

Commit

Permalink
improved Mojo::DOM::HTML to handle slash between attributes more grac…
Browse files Browse the repository at this point in the history
…efully
  • Loading branch information
kraih committed Feb 12, 2014
1 parent b2170e8 commit 551ebfe
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Changes
Expand Up @@ -4,7 +4,8 @@
- Added next_sibling and previous_sibling methods to Mojo::DOM.
- Added last method to Mojo::Collection.
- Improved many methods in Mojo::DOM to work with all node types.
- Improved Mojo::DOM::HTML performance.
- Improved Mojo::DOM::HTML to handle slash between attributes more
gracefully.
- Fixed list parsing bug in Mojo::DOM::HTML.

4.79 2014-02-11
Expand Down
8 changes: 4 additions & 4 deletions lib/Mojo/DOM/HTML.pm
Expand Up @@ -8,15 +8,15 @@ has 'xml';
has tree => sub { ['root'] };

my $ATTR_RE = qr/
([^<>=\s]+) # Key
([^<>=\s\/]+|\/) # Key
(?:
\s*=\s*
(?:
"([^"]*?)" # Quotation marks
"([^"]*?)" # Quotation marks
|
'([^']*?)' # Apostrophes
'([^']*?)' # Apostrophes
|
([^>\s]*) # Unquoted
([^>\s\/]*) # Unquoted
)
)?
\s*
Expand Down
8 changes: 8 additions & 0 deletions t/mojo/dom.t
Expand Up @@ -2295,6 +2295,14 @@ is $dom->find('div > ul li')->[2], undef, 'no result';
is $dom->find('div > ul ul')->[0]->text, 'C', 'right text';
is $dom->find('div > ul ul')->[1], undef, 'no result';

# Slash between attributes
$dom = Mojo::DOM->new('<input /type=checkbox/ value="/a/" checked/><br/>');
is $dom->at('input')->{type}, 'checkbox', 'right attribute';
is $dom->at('input')->{value}, '/a/', 'right attribute';
ok exists $dom->at('input')->{checked}, 'attribute exists';
is $dom->at('input')->{checked}, undef, 'right attribute';
is "$dom", '<input checked type="checkbox" value="/a/"><br>', 'right result';

# Extra whitespace
$dom = Mojo::DOM->new('< span>a< /span><b >b</b><span >c</ span>');
is $dom->at('span')->text, 'a', 'right text';
Expand Down

0 comments on commit 551ebfe

Please sign in to comment.