Commit 0a17aa60 authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez
Browse files

Bug 1781724 - Fix JSString::encodeUTF8Partial with some ropes. r=anba, a=dsmith

We can't exit early if src.IsEmpty() if the stack is non-empty.

Differential Revision: https://phabricator.services.mozilla.com/D152899
parent 6a6de594
Loading
Loading
Loading
Loading
+15 −7
Original line number Diff line number Diff line
@@ -167,6 +167,7 @@ concat.forEach(function(t) {
  checkUtf8Equal(rope, t.expected);
});

{
  var ab = newRope("a", "b");
  var abc = newRope(ab, "c");
  var ef = newRope("e", "f");
@@ -174,6 +175,13 @@ var def = newRope("d", ef);
  var abcdef = newRope(abc, def);
  var abcdefab = newRope(abcdef, ab);
  checkUtf8Equal(abcdefab, "abcdefab");
}

{
  var right = newRope("\ude0a", ".");
  var rope = newRope("\ud83d", right);
  checkUtf8Equal(rope, "\ud83d\ude0a.");
}

if (typeof reportCompare === "function")
  reportCompare(true, true);
+18 −19
Original line number Diff line number Diff line
@@ -214,9 +214,7 @@ mozilla::Maybe<mozilla::Tuple<size_t, size_t> > JSString::encodeUTF8Partial(
        }
        pendingLeadSurrogate = 0;
      }
      if (src.IsEmpty()) {
        return mozilla::Some(mozilla::MakeTuple(totalRead, totalWritten));
      }
      if (!src.IsEmpty()) {
        char16_t last = src[src.Length() - 1];
        if (unicode::IsLeadSurrogate(last)) {
          src = src.To(src.Length() - 1);
@@ -235,6 +233,7 @@ mozilla::Maybe<mozilla::Tuple<size_t, size_t> > JSString::encodeUTF8Partial(
          return mozilla::Some(mozilla::MakeTuple(totalRead, totalWritten));
        }
      }
    }
    if (stack.empty()) {
      break;
    }