Commit c69ea62 for mammothjs

commit c69ea62ed5e7d5ef046d7d00772d9bb7b100daf6
Author: Michael Williamson <mike@zwobble.org>
Date:   Sun Aug 9 14:52:51 2026 +0100

    Ignore numbering levels that use numStyleLink to refer to themselves

diff --git a/NEWS b/NEWS
index b4251ca..5f954c3 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,9 @@
 * Fix: on Windows, when an image's content type includes a backslash in the
   subpart, files may be written outside of the directory set by --output-dir.

+* Detect and ignore numbering levels that use numStyleLink to refer to
+  themselves.
+
 # 1.12.0

 * Handle hyperlinked wp:anchor and wp:inline elements.
diff --git a/lib/docx/numbering-xml.js b/lib/docx/numbering-xml.js
index 544ba52..9c86536 100644
--- a/lib/docx/numbering-xml.js
+++ b/lib/docx/numbering-xml.js
@@ -17,20 +17,29 @@ function Numbering(nums, abstractNums, styles) {
     );

     function findLevel(numId, level) {
+        return findLevelWithSeenNumIds(numId, level, {});
+    }
+
+    function findLevelWithSeenNumIds(numId, level, seenNumIds) {
+        if (seenNumIds[numId]) {
+            return null;
+        }
+        seenNumIds[numId] = true;
+
         var num = nums[numId];
-        if (num) {
-            var abstractNum = abstractNums[num.abstractNumId];
-            if (!abstractNum) {
-                return null;
-            } else if (abstractNum.numStyleLink == null) {
-                return abstractNums[num.abstractNumId].levels[level];
-            } else {
-                var style = styles.findNumberingStyleById(abstractNum.numStyleLink);
-                return findLevel(style.numId, level);
-            }
-        } else {
+        if (!num) {
             return null;
         }
+
+        var abstractNum = abstractNums[num.abstractNumId];
+        if (!abstractNum) {
+            return null;
+        } else if (abstractNum.numStyleLink == null) {
+            return abstractNums[num.abstractNumId].levels[level];
+        } else {
+            var style = styles.findNumberingStyleById(abstractNum.numStyleLink);
+            return findLevelWithSeenNumIds(style.numId, level, seenNumIds);
+        }
     }

     function findLevelByParagraphStyleId(styleId) {
diff --git a/test/docx/numbering-xml.tests.js b/test/docx/numbering-xml.tests.js
index 004e9ab..e98cdf7 100644
--- a/test/docx/numbering-xml.tests.js
+++ b/test/docx/numbering-xml.tests.js
@@ -152,6 +152,22 @@ test('when w:abstractNum has w:numStyleLink then style is used to find w:num', f
 });


+test('when w:abstractNum has self-recursive w:numStyleLink then level is not found', function() {
+    var numbering = readNumberingXml(
+        new XmlElement("w:numbering", {}, [
+            new XmlElement("w:abstractNum", {"w:abstractNumId": "100"}, [
+                new XmlElement("w:numStyleLink", {"w:val": "List1"})
+            ]),
+            new XmlElement("w:num", {"w:numId": "200"}, [
+                new XmlElement("w:abstractNumId", {"w:val": "100"})
+            ])
+        ]),
+        {styles: new stylesReader.Styles({}, {}, {}, {"List1": {numId: "200"}})}
+    );
+    duck.assertThat(numbering.findLevel("200", "0"), duck.equalTo(null));
+});
+
+
 // See: 17.9.23 pStyle (Paragraph Style's Associated Numbering Level) in ECMA-376, 4th Edition
 test('numbering level can be found by paragraph style ID', function() {
     var numbering = readNumberingXml(