Skip to content

Fix navigation braille in no-unsafe builds - #865

Closed
venkatesh6114 wants to merge 1 commit into
daisy:mainfrom
venkatesh6114:fix/no-unsafe-navigation-braille
Closed

venkatesh6114 wants to merge 1 commit into
daisy:mainfrom
venkatesh6114:fix/no-unsafe-navigation-braille

Conversation

@venkatesh6114

@venkatesh6114 venkatesh6114 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes a panic in get_navigation_braille when MathCAT is compiled with the no-unsafe feature.

When the navigation focus is below the outer <math> element, get_navigation_braille creates a temporary document and wraps the focused node in a new <math> element. Previously, the copied node was allocated in the original document and then appended to the temporary document.

The default backend happens to tolerate this cross-document insertion, but the no-unsafe backend uses document-local indices and can panic with an out-of-bounds error.

Changes

  • Add a no-unsafe-specific helper that recursively copies a MathML subtree into a specified destination document.
  • Use the destination-document copy when wrapping the current navigation focus in a temporary <math> element.
  • Preserve the existing copy_mathml path for builds without no-unsafe.
  • Add a feature-gated regression test that:
    • Sets MathML containing a focused child node.
    • Moves the navigation focus to that node.
    • Calls get_navigation_braille.
    • Verifies that the expected LaTeX output is returned without a panic.

Compatibility

The behavior change is limited to builds compiled with the no-unsafe feature:

#[cfg(feature = "no-unsafe")]

Fixes #827

Copy focused MathML nodes into the temporary document only when the no-unsafe backend is enabled. Preserve the existing default-feature path and add feature-gated regression coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Linux library size: 0.58 MiB (0.00%)
Revision Release liblibmathcat.so
Base (95892ab) 0.58 MiB (611,568 bytes)
PR (b01ca08) 0.58 MiB (611,568 bytes)
Change 0 bytes (0.00%)

Built with default features, Rust 1.96.0, and Ubuntu 24.04. Workflow run.

@moritz-gross
moritz-gross requested a review from NSoiffer October 19, 2026 22:43
@NSoiffer

Copy link
Copy Markdown
Collaborator

Thanks for spotting the bug and explaining what the problem is. I am committing a different fix (b13ec5a) that avoids the #[cfg(feature = "xxx")] usages and instead just adds the extra arg to the copy function. Ultimately, it is a little less code although changes are in a few more places. I used your test (without the feature flag so both versions are tested).

@NSoiffer NSoiffer closed this Oct 20, 2026
@github-project-automation github-project-automation Bot moved this from Triage to Done in MathCAT Project Board Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

GetNavigationBraille panics in no-unsafe builds due to cross-document node insertion

2 participants