Ver Fonte

Bugfix: `TypeError: o.getAttribute is not a function converse-chatview.js`

can cause messages to not appear.

* Check against null not Element.
* Avoid iterating over non-Element nodes
JC Brand há 6 anos atrás
pai
commit
3c924cb39c
2 ficheiros alterados com 13 adições e 9 exclusões
  1. 4 0
      CHANGES.md
  2. 9 9
      src/utils/html.js

+ 4 - 0
CHANGES.md

@@ -1,5 +1,9 @@
 # Changelog
 
+# Cherry-pick: 9c024757b6de5b408afe7204e0c2d1fc9800b15f
+
+- Bugfix: `TypeError: o.getAttribute is not a function converse-chatview.js` (can cause messages to not appear).
+
 ## 5.0.0 (2019-08-08)
 - BOSH support has been moved to a plugin.
 - Support for XEP-0410 to check whether we're still present in a room

+ 9 - 9
src/utils/html.js

@@ -227,7 +227,7 @@ u.calculateElementHeight = function (el) {
 
 u.getNextElement = function (el, selector='*') {
     let next_el = el.nextElementSibling;
-    while ((next_el instanceof Element) && !sizzle.matchesSelector(next_el, selector)) {
+    while (next_el !== null && !sizzle.matchesSelector(next_el, selector)) {
         next_el = next_el.nextElementSibling;
     }
     return next_el;
@@ -235,24 +235,24 @@ u.getNextElement = function (el, selector='*') {
 
 u.getPreviousElement = function (el, selector='*') {
     let prev_el = el.previousElementSibling;
-    while ((prev_el instanceof Element) && !sizzle.matchesSelector(prev_el, selector)) {
-        prev_el = prev_el.previousSibling
+    while (prev_el !== null && !sizzle.matchesSelector(prev_el, selector)) {
+        prev_el = prev_el.previousElementSibling
     }
     return prev_el;
 }
 
 u.getFirstChildElement = function (el, selector='*') {
     let first_el = el.firstElementChild;
-    while ((first_el instanceof Element) && !sizzle.matchesSelector(first_el, selector)) {
-        first_el = first_el.nextSibling
+    while (first_el !== null && !sizzle.matchesSelector(first_el, selector)) {
+        first_el = first_el.nextElementSibling
     }
     return first_el;
 }
 
 u.getLastChildElement = function (el, selector='*') {
     let last_el = el.lastElementChild;
-    while ((last_el instanceof Element) && !sizzle.matchesSelector(last_el, selector)) {
-        last_el = last_el.previousSibling
+    while (last_el !== null && !sizzle.matchesSelector(last_el, selector)) {
+        last_el = last_el.previousElementSibling
     }
     return last_el;
 }
@@ -288,7 +288,7 @@ u.hideElement = function (el) {
 
 u.ancestor = function (el, selector) {
     let parent = el;
-    while ((parent instanceof Element) && !sizzle.matchesSelector(parent, selector)) {
+    while (parent !== null && !sizzle.matchesSelector(parent, selector)) {
         parent = parent.parentElement;
     }
     return parent;
@@ -298,7 +298,7 @@ u.nextUntil = function (el, selector, include_self=false) {
     /* Return the element's siblings until one matches the selector. */
     const matches = [];
     let sibling_el = el.nextElementSibling;
-    while ((sibling_el instanceof Element) && !sibling_el.matches(selector)) {
+    while (sibling_el !== null && !sibling_el.matches(selector)) {
         matches.push(sibling_el);
         sibling_el = sibling_el.nextElementSibling;
     }