4685: RB.LinkifyUtils.linkifyChildren doesn't linkify flat lists of URLs in Firefox

kyz

What version are you running?

ReviewBoard 3.0.4

What's the URL of the page containing the problem?

Any page with a text editor

What steps will reproduce the problem?

  1. Edit a text editor field (e.g. review request -> description)
  2. Add text like below (URLs separated by linebreak... and for further edification, have more than one paragraph) and save the field

https://google.com
https://yahoo.com

https://bing.com
https://duckduckgo.com

What is the expected output? What do you see instead?

Expected output is all links are linkified.
Actual output is that only the first link in each paragraph is linkified.

What operating system are you using? What browser?

  • Linux. Firefox 59.0.2
  • Windows. Firefox ESR 52.7.3
  • Windows. Google Chrome 65.0.3325.181

Please provide any additional information below.

The problem is that linkChildren is not handling siblings correctly if one is replaced. DOM structure before:

nodeType=1 nodeName=PRE
- nodeType=1 nodeName=P
  - nodeType=3 (text node https://google.com)
  - nodeType=1 nodeName=BR
  - nodeType=3 (text node https://yahoo.com)
  - nodeType=1 nodeName=BR
- nodeType=1 nodeName=P
  - nodeType=3 (text node https://bing.com)
  - nodeType=1 nodeName=BR
  - nodeType=3 (text node https://duckduckgo.com)
  - nodeType=1 nodeName=BR

Instead of iterating through all four sibling nodes under the first P, linkChildren only iterates through the first one. Because the linkifyText gives a changed result back, it replaces the HTML content... this makes the loop variable, node, a stale reference, and only the newly replaced node has .nextSibling set to continue the iteration.

The following diff appears to fix the problem, by no longer referencing (stale) node.nextSibling but directly iterating through childNodes.

--- ./reviewboard/static/rb/js/utils/linkifyUtils.es6.js.orig 2018-04-04 12:27:37.974976735 +0100
+++ ./reviewboard/static/rb/js/utils/linkifyUtils.es6.js 2018-04-04 12:37:23.974976735 +0100
@@ -184,7 +184,7 @@
* by the captured bug ID.
*/
linkifyChildren(el, bugTrackerURL) {
- for (let node = el.childNodes[0]; node; node = node.nextSibling) {
+ for (var node of el.childNodes) {
if (node.nodeType === node.TEXT_NODE) {
if (node.textContent) {
const newText = RB.LinkifyUtils.linkifyText(

#1 kyz

The bug editor has mangled my sample text, what it should be is: https://google.com<NEWLINE>https://yahoo.com<NEWLINE><NEWLINE>https://bing.com<NEWLINE>https://duckduckgo.com<NEWLINE>, which renders as two paragraphs in ReviewBoard, each paragraph having two lines separated by a linebreak.

#2 kyz

Splat loses track of bugs (as reported in bug 4695). Adding an update just to see if it doing that puts the bug back on the bug list.

david
#3 david
  • +Component:Reviews
    +EasyFix
cdkushni
#4 cdkushni

I'll work on this one.

david
#5 david

Fixed in release-3.0.x (7a92207). This will ship in 3.0.10. Thanks!

  • -New
    +Fixed