Skip to content

github.com - GitHub "Quote Reply" adds extra empty lines in Firefox, removes empty lines in Edge #28521

Open

Description

@cpeterso

URL: https://github.com/

Browser / Version: Firefox 68.0
Operating System: Windows 10
Tested Another Browser: Yes

Problem type: Something else
Description: GitHub "Quote Reply" adds extra empty lines in Firefox, removes empty lines in Edge
Steps to Reproduce:
STR:

  1. Load an existing GitHub issue.
  2. Select "Quote Reply" on a comment that has multiple paragraphs or newlines.

RESULT:

  • Firefox will prepend two empty > lines before the quoted reply. I tested Firefox 66 Release and 68 Nightly.
  • Edge will remove empty lines between paragraphs.
  • Chrome does the right thing. It doesn't add or remove any empty lines.
Browser Configuration
  • None

From webcompat.com with ❤️

Activity

  1. added this to the needstriage milestone on Mar 28, 2019
  2. changed the title [-]github.com - see bug description[/-] [+]github.com - GitHub "Quote Reply" adds extra empty lines in Firefox, removes empty lines in Edge[/+] on Apr 8, 2019
  3. added
    severity-important
    on Apr 8, 2019
  4. softvision-sergiulogigan commented on Apr 8, 2019

    @softvision-sergiulogigan

    Thanks @cpeterso for this one! I can reproduce this issue.

    Tested with:
    Browser / Version: Firefox Nightly 68.0a1 (2019-04-07)
    Operating System: Windows 10 Pro

    image

  5. self-assigned this
    on Apr 9, 2019
  6. karlcow commented on Apr 9, 2019

    @karlcow
    Member

    I have a hunch it is mildly related with the quote reply specifically, but with the text representation of content. It reminds me of https://bugzilla.mozilla.org/show_bug.cgi?id=1174452

    Note also the additional line is happening only for lists, aka the rest is getting a normal treatment.

    For example, a simple copy/paste of

    data:text/html,<ol><li>a</li><li>b</li><li>c</li></ol>
    

    select, copy and then paste into (where I put the cursor to the empty line )

    ---firefox
    
    ---chrome
    
    ---end
    

    then I get:

    ---firefox
        a
        b
        c
    ---chrome
    a
    b
    c
    ---end
    

    we can see the treatment is different.

    Also

    document.getElementsByTagName('ol')[0].textContent
    "abc"
    document.getElementsByTagName('ol')[0].innerText
    "a
    b
    c"
    

    The quote reply is:

              r("click", ".js-comment-quote-reply", function(e) {
                let t = e.currentTarget;
                const o = s(t, ".js-comment"),
                  r = n(o, ".js-comment-body");
                if (Jn && "Range" === Jn.type && r.contains(Jn.anchorNode))
                  Wn(Jn.text, Jn.range);
                else {
                  const e = window.getSelection();
                  e.removeAllRanges(),
                    e.selectAllChildren(r),
                    Wn(e.toString(), e.getRangeAt(0));
                }
              }),
  7. karlcow commented on Apr 9, 2019

    @karlcow
    Member

    In the previous comment, it will call Wn after serializing with toString(), It seems that toString() serializes differently in Chrome and Firefox.

            function Wn(e, t) {
              var n = (function(e, t, n) {
                var s = e.trim();
                if (!s) return;
                var o = t.startContainer;
                if (!o) return;
                o.nodeType !== Node.ELEMENT_NODE && (o = o.parentNode);
                if (!(o instanceof Element)) return;
                var r = Un(o);
                if (!r) return;
                var i = r.getAttribute("data-quote-markdown");
                if (null != i && !On)
                  try {
                    s = (function(e) {
                      var t = document.body;
                      if (!t) return "";
                      var n = document.createElement("div");
                      n.appendChild(e),
                        (n.style.cssText = "position:absolute;left:-9999px;"),
                        t.appendChild(n);
                      var s = "";
                      try {
                        var o = window.getSelection(),
                          r = document.createRange();
                        r.selectNodeContents(n),
                          o.removeAllRanges(),
                          o.addRange(r),
                          (s = o.toString()),
                          o.removeAllRanges(),
                          r.detach();
                      } finally {
                        t.removeChild(n);
                      }
                      return s;
                    })(
                      (function(e, t, n) {
                        var s = e.startContainer;
                        if (
                          !(
                            s &&
                            s.parentNode &&
                            s.parentNode instanceof HTMLElement
                          )
                        )
                          throw new Error(
                            "the range must start within an HTMLElement"
                          );
                        var o = s.parentNode,
                          r = e.cloneContents();
                        if (t) {
                          var i = r.querySelector(t);
                          i &&
                            (r = document.createDocumentFragment()).appendChild(i);
                        }
                        $n = 0;
                        var a = o.closest("li"),
                          c = o.closest("pre");
                        if (c) {
                          var l = document.createElement("pre");
                          l.appendChild(r);
                          var u = l;
                          if (!n) {
                            var d = c.parentNode;
                            if (d instanceof HTMLElement && _n(d)) {
                              var m = document.createElement("div");
                              (m.className = d.className),
                                m.appendChild(u),
                                (u = m);
                            }
                          }
                          (r = document.createDocumentFragment()).appendChild(u);
                        } else if (
                          a &&
                          a.parentNode &&
                          ("OL" === a.parentNode.nodeName && ($n = In(a)),
                          !r.querySelector("li"))
                        ) {
                          var f = document.createElement("li");
                          if (!a.parentNode) throw new Error();
                          var g = document.createElement(a.parentNode.nodeName);
                          f.appendChild(r),
                            g.appendChild(f),
                            (r = document.createDocumentFragment()).appendChild(g);
                        }
                        return (
                          Bn(r, function(e, t) {
                            return e.replaceWith(t);
                          }),
                          r
                        );
                      })(t, i, n)
                    )
                      .replace(/^\n+/, "")
                      .replace(/\s+$/, "");
                  } catch (a) {
                    setTimeout(function() {
                      throw a;
                    });
                  }
                return { selectionText: s, container: r };
              })(e, t, !1);
              if (!n) return !1;
              var s = n.container,
                o = n.selectionText;
              if (
                !s.dispatchEvent(
                  new CustomEvent("quote-selection", {
                    bubbles: !0,
                    cancelable: !0,
                    detail: { range: t, selectionText: o }
                  })
                )
              )
                return !0;
              var r = zn(s);
              return (
                !!r &&
                ((function(e, t) {
                  var n = "> ".concat(e.replace(/\n/g, "\n> "), "\n\n");
                  t.value && (n = "".concat(t.value, "\n\n").concat(n));
                  (t.value = n),
                    t.dispatchEvent(
                      new CustomEvent("change", { bubbles: !0, cancelable: !1 })
                    ),
                    t.focus(),
                    (t.selectionStart = t.value.length),
                    (t.scrollTop = t.scrollHeight);
                })(o, r),
                !0)
              );
            }

    My interpretation is that it serializes the text given by toString()

    for example

    data:text/html,<ol>%0A<li>A</li>%0A<li>B</li>%0A</ol>
    

    serialized with Chrome

    const e = window.getSelection()
    undefined
    e.getRangeAt(0)
    Range {startContainer: text, startOffset: 0, endContainer: text, endOffset: 1, collapsed: false, …}
    e.toString()
    "A
    B"
    

    and with Firefox

    const e = window.getSelection()
    undefined
    e.getRangeAt(0)
    Range { startContainer: body, startOffset: 0, endContainer: body, endOffset: 1, collapsed: false, commonAncestorContainer: body
     }
    
    e.toString()
    "
        A
        B
    "
    

    I don't know if there is an open bug on Mozilla bugzilla for differences of toString.

  8. karlcow commented on Apr 9, 2019

    @karlcow
    Member

    I will advertise this issue on the bugzilla issue, but I think we should contact GitHub, because I have the feeling that changing behavior of getSelection ot toString would create an armageddon of issues.

  9. miketaylr commented on Apr 22, 2019

    @miketaylr
    Member

    I sent an email to GitHub support -- I'm not really sure where this feature would live (if it's even open source), but they tend to be super helpful.

  10. removed their assignment
    on Apr 30, 2019
  11. added
    engine-gecko
    on Apr 30, 2019
  12. karlcow commented on May 20, 2019

    @karlcow
    Member

    The behavior didn't change here so the mail for contact didn't work. @miketaylr also opened another issue which I think is related. #30041

  13. cpeterso commented on Jun 9, 2019

    @cpeterso
    Author

    This bug seems to have been fixed on GitHub's side. I can't reproduce the bug in Firefox 67 or 69 Nightly, where previously I could reproduce in Firefox 68 and earlier. I'll close this issue.

  14. cpeterso commented on Jun 9, 2019

    @cpeterso
    Author

    IIUC, I think checkbox reply issue #30041 is also fixed.

  15. cipriansv commented on Jun 12, 2019

    @cipriansv

    I retested the issue and it is still reproducible on my side.

    image

    Tested with:
    Browser / Version: Firefox Nightly 69.0a1 (2019-06-11)
    Operating System: Windows 10 Pro

  16. cpeterso commented on Jun 12, 2019

    @cpeterso
    Author

    I retested the issue and it is still reproducible on my side.

    Reopening this issue because I can reproduce this bug again, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    browser-firefoxengine-geckopriority-criticalseverity-important

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions