WebReflection / basicHTML

A NodeJS based, standard oriented, HTML implementation.
ISC License
126 stars 10 forks source link

Regression in v2.3.0: duplicate <html><html>…</html></html> #51

Closed nhoizey closed 4 years ago

nhoizey commented 4 years ago

I'm loading full HTML documents in BasicHTML, with DOCTYPE and <html>, and it used to work properly up to v2.2.9

Now, in v2.3.0, document.toString() gives me a duplicate <html><html>…</html></html>.

Sample script:

const basicHTML = require('basichtml');
const { document } = basicHTML.init();

const html = "<!DOCTYPE html><html><body><p>Hello</p></body></html>";
document.documentElement.innerHTML = html;
console.dir(document.toString());

Outputs this in v2.2.9: <!DOCTYPE html><html><body><p>Hello</p></body></html>

Outputs this in v2.3.0: <!DOCTYPE html><html><html><body><p>Hello</p></body></html></html>

WebReflection commented 4 years ago

this looks like expected, as document.documentElement is already the <html> tag by standards.

You are injecting an <html> tag within an <html> node, so what you call a regression, is actually a logical fix to me, hence I don't think I should do anything in here.

nhoizey commented 4 years ago

Ok, I can understand it's a fix instead of a regression.

Would you have any advice to clean the html string before document.documentElement.innerHTML = html;, or use anything else than document.documentElement.innerHTML =…?

Don't you ever use BasicHTML on full documents?

Thanks

WebReflection commented 4 years ago

maybe this?

document.documentElement.innerHTML = html.replace(/^[\S\s]*?<html[\S\s]*?>([\S\s]*?)<\/html>/i, '$1');
nhoizey commented 4 years ago

@WebReflection I will check this, thanks a lot! 🙏

WebReflection commented 4 years ago

alternative solution in here: https://github.com/nhoizey/images-responsiver/issues/72#issuecomment-684764424

nhoizey commented 4 years ago

@WebReflection hi Andrea, sorry to bother you here once again.

I still can't find how to use Sizzle with the code you provided in https://github.com/nhoizey/images-responsiver/issues/72#issuecomment-686762982

Thanks for your help! 🙏

WebReflection commented 4 years ago

@nhoizey yeah, that part is a bit of a shenanigan ... but for the time being, you can try this solution, I hope it works.