Skip to content

Commit 7dd57f8

Browse files
fix(super-editor): guard against style definition nodes without elements (#2379)
1 parent fa8afc8 commit 7dd57f8

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

packages/super-editor/src/core/super-converter/docx-helpers/get-default-style-definition.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export const getDefaultStyleDefinition = (defaultStyleId, docx) => {
2424
const firstMatch = elementsWithId[0];
2525
if (!firstMatch) return result;
2626

27+
if (!firstMatch.elements) return result;
28+
2729
const qFormat = elementsWithId.find((el) => {
2830
const qFormat = el.elements.find((innerEl) => innerEl.name === 'w:qFormat');
2931
return qFormat;

packages/super-editor/src/core/super-converter/docx-helpers/get-default-style-definition.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,28 @@ describe('getDefaultStyleDefinition', () => {
3838
expect(res).toEqual({ lineSpaceBefore: null, lineSpaceAfter: null });
3939
});
4040

41+
it('returns minimal object when matching style has no elements', () => {
42+
const docx = {
43+
'word/styles.xml': {
44+
elements: [
45+
{
46+
elements: [
47+
{
48+
name: 'w:style',
49+
attributes: { 'w:styleId': 'Heading1' },
50+
},
51+
],
52+
},
53+
],
54+
},
55+
};
56+
57+
const res = getDefaultStyleDefinition('Heading1', docx);
58+
59+
expect(res).toEqual({ lineSpaceBefore: null, lineSpaceAfter: null });
60+
expect(parseMarks).not.toHaveBeenCalled();
61+
});
62+
4163
it('parses style definition with spacing, indent, flags, and marks', () => {
4264
const docx = {
4365
'word/styles.xml': {

0 commit comments

Comments
 (0)