From 6f889454d0436fc17e831b767ab7d993b3d06f45 Mon Sep 17 00:00:00 2001 From: Ryan Grove Date: Thu, 21 Sep 2017 14:41:08 -0700 Subject: [PATCH] Fix error when pasted HTML includes a doctype (#1160) * Fix error when pasted HTML includes a doctype When pasted HTML includes a doctype definition, `parsed.childNodes[0]` is the doctype node, not the `` node, so it's not safe to assume that `parsed.childNodes[0].childNodes[1]` is the `` node. Using `parsed.body` ensures that we always get the `` node no matter where it is in the document. * Update index.js --- packages/slate-html-serializer/src/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/slate-html-serializer/src/index.js b/packages/slate-html-serializer/src/index.js index 7570fc7c2..1359fedca 100644 --- a/packages/slate-html-serializer/src/index.js +++ b/packages/slate-html-serializer/src/index.js @@ -59,7 +59,8 @@ const TEXT_RULE = { } /** - * A default `parseHtml` option using the native `DOMParser`. + * A default `parseHtml` function that returns the `` using the + * native `DOMParser`. * * @param {String} html * @return {Object} @@ -71,9 +72,8 @@ function defaultParseHtml(html) { } const parsed = new DOMParser().parseFromString(html, 'text/html') - // Unwrap from and . - const fragment = parsed.childNodes[0].childNodes[1] - return fragment + const { body } = parsed + return body } /**