summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@wolfbeast.com>2019-12-06 14:54:57 +0100
committerwolfbeast <mcwerewolf@wolfbeast.com>2019-12-06 14:54:57 +0100
commite287979b3eedb2c67a3c6da2991fdb56a4d35742 (patch)
tree34c94349f2099892901235e110403d29b9431c47
parent5d4c82e0923e63077738ba4b63ab290810537f11 (diff)
downloadUXP-e287979b3eedb2c67a3c6da2991fdb56a4d35742.tar
UXP-e287979b3eedb2c67a3c6da2991fdb56a4d35742.tar.gz
UXP-e287979b3eedb2c67a3c6da2991fdb56a4d35742.tar.lz
UXP-e287979b3eedb2c67a3c6da2991fdb56a4d35742.tar.xz
UXP-e287979b3eedb2c67a3c6da2991fdb56a4d35742.zip
Fix incorrect values for saving ordered lists as text.
-rw-r--r--dom/base/nsPlainTextSerializer.cpp58
-rw-r--r--dom/base/nsPlainTextSerializer.h4
2 files changed, 33 insertions, 29 deletions
diff --git a/dom/base/nsPlainTextSerializer.cpp b/dom/base/nsPlainTextSerializer.cpp
index 8097c4ec8..98c9cfe32 100644
--- a/dom/base/nsPlainTextSerializer.cpp
+++ b/dom/base/nsPlainTextSerializer.cpp
@@ -53,7 +53,6 @@ static int32_t GetUnicharStringWidth(const char16_t* pwcs, int32_t n);
// Someday may want to make this non-const:
static const uint32_t TagStackSize = 500;
-static const uint32_t OLStackSize = 100;
nsresult
NS_NewPlainTextSerializer(nsIContentSerializer** aSerializer)
@@ -100,10 +99,6 @@ nsPlainTextSerializer::nsPlainTextSerializer()
mTagStackIndex = 0;
mIgnoreAboveIndex = (uint32_t)kNotFound;
- // initialize the OL stack, where numbers for ordered lists are kept
- mOLStack = new int32_t[OLStackSize];
- mOLStackIndex = 0;
-
mULCount = 0;
mIgnoredChildNodeLevel = 0;
@@ -112,7 +107,6 @@ nsPlainTextSerializer::nsPlainTextSerializer()
nsPlainTextSerializer::~nsPlainTextSerializer()
{
delete[] mTagStack;
- delete[] mOLStack;
NS_WARNING_ASSERTION(mHeadLevel == 0, "Wrong head level!");
}
@@ -189,6 +183,8 @@ nsPlainTextSerializer::Init(uint32_t aFlags, uint32_t aWrapColumn,
// XXX We should let the caller decide whether to do this or not
mFlags &= ~nsIDocumentEncoder::OutputNoFramesContent;
+ MOZ_ASSERT(mOLStack.IsEmpty());
+
return NS_OK;
}
@@ -438,6 +434,8 @@ nsPlainTextSerializer::AppendDocumentStart(nsIDocument *aDocument,
return NS_OK;
}
+int32_t kOlStackDummyValue = 0;
+
nsresult
nsPlainTextSerializer::DoOpenContainer(nsIAtom* aTag)
{
@@ -616,44 +614,45 @@ nsPlainTextSerializer::DoOpenContainer(nsIAtom* aTag)
}
else if (aTag == nsGkAtoms::ul) {
// Indent here to support nested lists, which aren't included in li :-(
- EnsureVerticalSpace(mULCount + mOLStackIndex == 0 ? 1 : 0);
- // Must end the current line before we change indention
+ EnsureVerticalSpace(IsInOLOrUL() ? 0 : 1);
+ // Must end the current line before we change indention
mIndent += kIndentSizeList;
mULCount++;
}
else if (aTag == nsGkAtoms::ol) {
- EnsureVerticalSpace(mULCount + mOLStackIndex == 0 ? 1 : 0);
+ EnsureVerticalSpace(IsInOLOrUL() ? 0 : 1);
if (mFlags & nsIDocumentEncoder::OutputFormatted) {
// Must end the current line before we change indention
- if (mOLStackIndex < OLStackSize) {
- nsAutoString startAttr;
- int32_t startVal = 1;
- if (NS_SUCCEEDED(GetAttributeValue(nsGkAtoms::start, startAttr))) {
- nsresult rv = NS_OK;
- startVal = startAttr.ToInteger(&rv);
- if (NS_FAILED(rv))
- startVal = 1;
+ nsAutoString startAttr;
+ int32_t startVal = 1;
+ if (NS_SUCCEEDED(GetAttributeValue(nsGkAtoms::start, startAttr))) {
+ nsresult rv = NS_OK;
+ startVal = startAttr.ToInteger(&rv);
+ if (NS_FAILED(rv)) {
+ startVal = 1;
}
- mOLStack[mOLStackIndex++] = startVal;
}
+ mOLStack.AppendElement(startVal);
} else {
- mOLStackIndex++;
+ mOLStack.AppendElement(kOlStackDummyValue);
}
mIndent += kIndentSizeList; // see ul
}
else if (aTag == nsGkAtoms::li &&
(mFlags & nsIDocumentEncoder::OutputFormatted)) {
if (mTagStackIndex > 1 && IsInOL()) {
- if (mOLStackIndex > 0) {
+ if (!mOLStack.IsEmpty()) {
nsAutoString valueAttr;
if (NS_SUCCEEDED(GetAttributeValue(nsGkAtoms::value, valueAttr))) {
nsresult rv = NS_OK;
int32_t valueAttrVal = valueAttr.ToInteger(&rv);
- if (NS_SUCCEEDED(rv))
- mOLStack[mOLStackIndex-1] = valueAttrVal;
+ if (NS_SUCCEEDED(rv)) {
+ mOLStack.LastElement() = valueAttrVal;
+ }
}
// This is what nsBulletFrame does for OLs:
- mInIndentString.AppendInt(mOLStack[mOLStackIndex-1]++, 10);
+ mInIndentString.AppendInt(mOLStack.LastElement(), 10);
+ mOLStack.LastElement()++;
}
else {
mInIndentString.Append(char16_t('#'));
@@ -878,7 +877,8 @@ nsPlainTextSerializer::DoCloseContainer(nsIAtom* aTag)
else if (aTag == nsGkAtoms::ul) {
FlushLine();
mIndent -= kIndentSizeList;
- if (--mULCount + mOLStackIndex == 0) {
+ --mULCount;
+ if (!IsInOLOrUL()) {
mFloatingLines = 1;
mLineBreakDue = true;
}
@@ -886,9 +886,9 @@ nsPlainTextSerializer::DoCloseContainer(nsIAtom* aTag)
else if (aTag == nsGkAtoms::ol) {
FlushLine(); // Doing this after decreasing OLStackIndex would be wrong.
mIndent -= kIndentSizeList;
- NS_ASSERTION(mOLStackIndex, "Wrong OLStack level!");
- mOLStackIndex--;
- if (mULCount + mOLStackIndex == 0) {
+ NS_ASSERTION(!mOLStack.IsEmpty(), "Wrong OLStack level!");
+ mOLStack.RemoveElementAt(mOLStack.Length() - 1);
+ if (!IsInOLOrUL()) {
mFloatingLines = 1;
mLineBreakDue = true;
}
@@ -1861,6 +1861,10 @@ nsPlainTextSerializer::IsInOL()
return false;
}
+bool nsPlainTextSerializer::IsInOLOrUL() const {
+ return (mULCount > 0) || !mOLStack.IsEmpty();
+}
+
/*
@return 0 = no header, 1 = h1, ..., 6 = h6
*/
diff --git a/dom/base/nsPlainTextSerializer.h b/dom/base/nsPlainTextSerializer.h
index 5055c75a0..650a8e3e7 100644
--- a/dom/base/nsPlainTextSerializer.h
+++ b/dom/base/nsPlainTextSerializer.h
@@ -81,6 +81,7 @@ private:
void Write(const nsAString& aString);
bool IsInPre();
bool IsInOL();
+ bool IsInOLOrUL() const;
bool IsCurrentNodeConverted();
bool MustSuppressLeaf();
@@ -218,8 +219,7 @@ private:
uint32_t mIgnoreAboveIndex;
// The stack for ordered lists
- int32_t *mOLStack;
- uint32_t mOLStackIndex;
+ AutoTArray<int32_t, 100> mOLStack;
uint32_t mULCount;