Skip to content

el.replace escapes &#x27; but not < or >, which is different than Mojo::DOM #27

@akarelas

Description

@akarelas
import DOM from '@mojojs/dom';

let dom = new DOM('<div><p>Alex</p></div>');
dom.at('div').replace('<b>1</b>');
console.log(dom.toString()); // prints: <b>1</b>

dom = new DOM('<div><p>Alex</p></div>');
dom.at('div').replace('&#x27;hi');
console.log(dom.toString()); // prints: &amp;#x27;hi

First replace invocation doesn't escape < or >, whereas second snippet escapes &. This behavior is inconsistent with Mojo::DOM, as can be shown by the following piece of code:

use Mojo::DOM;

my $dom = Mojo::DOM->new('<div><p>Alex</p></div>');
$dom->at('div')->replace('<b>1</b>');
say $dom->to_string; # prints <b>1</b>

$dom = Mojo::DOM->new('<div><p>Alex</p></div>');
$dom->at('div')->replace('&#x27;hi');
say $dom->to_string; # prints &#39;hi which is equivalent to &#x27;hi

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions