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

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

Open
akarelas opened this issue Dec 18, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@akarelas
Copy link

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
@akarelas akarelas changed the title el.replace escapes & but not < or >, which is different than Mojo::DOM el.replace escapes &#x27; but not < or >, which is different than Mojo::DOM Dec 18, 2023
@kraih
Copy link
Member

kraih commented Dec 18, 2023

Isn't there an existing Mojo::DOM test that covers the case already?

@akarelas
Copy link
Author

I don't know, but in the JS lib, the bug only appears with entities matching &#x (the x is necessary).

Whereas Mojo::DOM's tests don't contain &#x anywhere.

@akarelas
Copy link
Author

The same issue (i.e. &#x27; being escaped in JS) also appears with the replaceContent (vs Mojo::DOM's content method, which doesn't escape it):

import DOM from '@mojojs/dom';

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

@kraih kraih added the bug Something isn't working label Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants