Skip to content

fix: add null checks to list numbering functions#1904

Open
lloyd-lighthouse wants to merge 1 commit intosuperdoc-dev:mainfrom
lighthousenz:fix/list-numbering-null-check
Open

fix: add null checks to list numbering functions#1904
lloyd-lighthouse wants to merge 1 commit intosuperdoc-dev:mainfrom
lighthousenz:fix/list-numbering-null-check

Conversation

@lloyd-lighthouse
Copy link

Summary

Added null safety to the list numbering functions in shared/common/list-numbering/index.ts to prevent runtime errors when lvlText is null or undefined.

Changes

  • Updated createNumbering to accept lvlText: string | null and return early if null
  • Updated generateNumbering to accept lvlText: string | null with null guard
  • Updated generateFromCustom to accept lvlText: string | null with null guard
  • Updated return types to string | null to reflect nullable returns

Why

When lvlText is null, calling .replace() on it causes a runtime error. This fix ensures graceful handling by returning null early.

Test Plan

  • Existing unit tests pass
  • Verify list numbering still works correctly with valid lvlText values
  • Verify null lvlText returns null without throwing errors

Breaking Changes

None - this is a backwards-compatible fix. Functions that previously crashed on null input will now return null.

Added null safety to createNumbering, generateNumbering, and
generateFromCustom functions to prevent runtime errors when
lvlText is null or undefined.
@lloyd-lighthouse
Copy link
Author

Hi team.

Its strange that a version was released to fix numbering issues recently (#1675)

However this is a similar issue, perhaps some sort of an edge case?


This document works
broken-numbering-missing-abstract.docx

This document however, does not work
document-2026-02-02 (2).docx


We've tried our best to trace this issue down and think the suggested fix in this PR is a way for us to make sure we never encounter this issue again, but we are obviously new to this codebase and can only do a best guess realistically.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant