Skip to content

Handle empty ProForma formulas#98

Merged
douweschulte merged 1 commit into
rusteomics:mainfrom
BioGeek:pro-forma-empty-formula
Jun 22, 2026
Merged

Handle empty ProForma formulas#98
douweschulte merged 1 commit into
rusteomics:mainfrom
BioGeek:pro-forma-empty-formula

Conversation

@BioGeek

@BioGeek BioGeek commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

This PR fixes an existing mzcore ProForma molecular formula parser panic for empty input.

Previously, MolecularFormula::pro_forma::<_, true>("") could attempt an inclusive slice on an empty string and panic, even though empty formulas are documented as valid when ALLOW_EMPTY is enabled.

Changes:

  • Detect empty input before slicing the requested formula range.

  • Preserve existing behavior:

    • empty formulas return Ok(default) when ALLOW_EMPTY = true
    • empty formulas return an error when ALLOW_EMPTY = false
  • Add regression coverage for both accepted and rejected empty input.

Validated xith:

CARGO_INCREMENTAL=0 cargo test -p mzcore --doc MolecularFormula::pro_forma --no-fail-fast
CARGO_INCREMENTAL=0 cargo test -p mzcore pro_forma_empty --lib --no-fail-fast

Both pass.

@douweschulte

Copy link
Copy Markdown
Member

Thanks for the fix. I think I inadvertently broke this recently when cleaning up this region of code.

@douweschulte douweschulte merged commit 9c2d4ee into rusteomics:main Jun 22, 2026
3 of 4 checks passed
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.

2 participants