Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mojo::DOM's ->wrap does not work on ->at'ed or ->find'ed elements #877

Closed
zoffixznet opened this issue Nov 26, 2015 · 2 comments
Closed

Comments

@zoffixznet
Copy link
Contributor

Problem

If your Mojo::DOM object was obtained using ->at or ->find Mojo::DOM's methods, the ->wrap method stops working.

Demo

#!/usr/bin/env perl

use strict;
use warnings;
use Mojo::DOM;
use 5.010;

my $d = Mojo::DOM->new(q{<h1><a href="42">Foo</a></h1>});
my $bug = $d->at('h1');
my $working = Mojo::DOM->new($bug);

say "$bug\n\n";
say "$working\n\n";

say $bug->wrap('<div></div>') . "\n\n";
say $working->wrap('<div></div>');

Expected Results

<h1><a href="42">Foo</a></h1>


<h1><a href="42">Foo</a></h1>


<div><h1><a href="42">Foo</a></h1></div>


<div><h1><a href="42">Foo</a></h1></div>

Current Results

<h1><a href="42">Foo</a></h1>


<h1><a href="42">Foo</a></h1>


<h1><a href="42">Foo</a></h1>


<div><h1><a href="42">Foo</a></h1></div>

As you can see, the third line is not wrapped in a <div>, even though it should be.

Misc

When playing around with slightly different markup, I got these warnings to pop up:

Use of uninitialized value in string eq at /home/zoffix/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/Mojo/DOM.pm line 312.
splice() offset past end of array at /home/zoffix/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/Mojo/DOM.pm line 286.

I believe the ->ated portion of the markup was:

<div class="section even"><h1>UTC-12</h1><div class="cloud scloud w90"><ul><li id="c0"><a class="s1 country multizone bold" href="U.S._Minor_Outlying_Islands" onmouseout="hvr(0)" onmouseover="hvr(0,1)">Illes Perif�riques Menors dels EUA</a>
<ul>
<li><a class="s2" href="Baker_Island">Baker Island</a></li>
<li><a class="s2" href="Howland_Island">Howland Island</a></li>
</ul></li>
</ul></div></div>

Versions

zoffix@ZofMain:~$ perl -v

This is perl 5, version 22, subversion 0 (v5.22.0) built for i686-linux

Copyright 1987-2015, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

zoffix@ZofMain:~$ perl -MMojolicious -wlE 'say Mojolicious->VERSION'
6.33
zoffix@ZofMain:~$ 
@kraih
Copy link
Member

kraih commented Nov 26, 2015

I'm afraid nothing here looks like a bug to me, you seem to be making assumptions about the return value of $dom->wrap(...) i can't quite follow.

@zoffixznet
Copy link
Contributor Author

If anyone stumbles onto this in the future, this is the conversation that explains why the bug is not a bug: http://irclog.perlgeek.de/mojo/2015-11-26#i_11600930

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants