Skip to content

[Bug] Formatted numeric parsing silently accepts trailing garbage #1152

Closed

Description

@Aias00

Fesod version

Current main at 5a9a16b.

Description

When a field has a number format, NumberUtils parses numeric strings with DecimalFormat#parse(String) but does not verify that the full input was consumed. A valid numeric prefix is accepted and trailing invalid text is silently discarded.

Location

fesod-sheet/src/main/java/org/apache/fesod/sheet/util/NumberUtils.java:226-231

Reproduction

ExcelContentProperty property = new ExcelContentProperty();
property.setNumberFormatProperty(new NumberFormatProperty("#,##0.00", RoundingMode.HALF_UP));

NumberUtils.parseBigDecimal("1,234.56abc", property);
// returns 1234.56

NumberUtils.parseBigDecimal("1,234.56abc", null);
// throws NumberFormatException

Expected behavior

Malformed numeric strings should fail conversion rather than being partially accepted. Literal prefixes or suffixes that are part of the configured format should continue to parse normally.

Suggested fix

Parse with ParsePosition, require a successful parse and position.getIndex() == input.length(), and add tests for all numeric target families plus configured literal suffixes.

Related existing work

#1100/#1101 cover range checks for numeric cells. They do not cover incomplete parsing of formatted string cells.

Are you willing to submit a PR?

Yes.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions