jenkins-bot has submitted this change and it was merged. Change subject: Don't drop <html> attributes when parsing HTML on Opera 12 ......................................................................
Don't drop <html> attributes when parsing HTML on Opera 12 They used to be unimportant, but since 9019f02130513943661e5705286720e6deaf1b67 we're actually checking the value of one of them ('about'). Bug: T96435 Change-Id: I105cb76ec8d846f90789df97511f960d4312074a --- M src/ve.utils.js 1 file changed, 16 insertions(+), 5 deletions(-) Approvals: Catrope: Looks good to me, approved jenkins-bot: Verified diff --git a/src/ve.utils.js b/src/ve.utils.js index 3c476b0..3377050 100644 --- a/src/ve.utils.js +++ b/src/ve.utils.js @@ -773,7 +773,7 @@ ve.createDocumentFromHtml = function ( html ) { // Try using DOMParser if available. This only works in Firefox 12+ and very modern // versions of other browsers (Chrome 30+, Opera 17+, IE10+) - var newDocument, $iframe, iframe; + var newDocument, $iframe, iframe, xmlDoc, i; try { if ( html === '' ) { // IE doesn't like empty strings @@ -831,10 +831,21 @@ // *is* a document. This only happens when debugging with Dragonfly.) newDocument = document.implementation.createHTMLDocument( '' ); // Carefully unwrap the HTML out of the root node (and doctype, if any). - // <html> might have some arguments here, but they're apparently not important. - html = html.replace(/^\s*(?:<!doctype[^>]*>)?\s*<html[^>]*>/i, '' ); - html = html.replace(/<\/html>\s*$/i, '' ); - newDocument.documentElement.innerHTML = html; + newDocument.documentElement.innerHTML = html + .replace(/^\s*(?:<!doctype[^>]*>)?\s*<html[^>]*>/i, '' ) + .replace(/<\/html>\s*$/i, '' ); + // Preserve <html> attributes, if any + try { + xmlDoc = new DOMParser().parseFromString( html, 'text/xml' ); + if ( xmlDoc.documentElement.tagName.toLowerCase() === 'html' ) { + for ( i = 0; i < xmlDoc.documentElement.attributes.length; i++ ) { + newDocument.documentElement.setAttribute( + xmlDoc.documentElement.attributes[i].name, + xmlDoc.documentElement.attributes[i].value + ); + } + } + } catch ( e ) { } } return newDocument; -- To view, visit https://gerrit.wikimedia.org/r/204944 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I105cb76ec8d846f90789df97511f960d4312074a Gerrit-PatchSet: 1 Gerrit-Project: VisualEditor/VisualEditor Gerrit-Branch: master Gerrit-Owner: Bartosz DziewoĆski <matma....@gmail.com> Gerrit-Reviewer: Catrope <roan.katt...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits