Skip to content

Case-Sensitivity Enum Parsing Bug in ExcelChartAxisStandard MajorTickMark and MinorTickMark #2369

@lievendf

Description

@lievendf

Epplus version

8.6.0.0

Description

There is a case-sensitivity mismatch inside ExcelChartAxisStandard (under OfficeOpenXml.Drawing.Chart) when reading and writing the MajorTickMark and MinorTickMark properties:

  1. Write (Setter): Setting the value (e.g. eAxisTickMark.In or eAxisTickMark.Out) lowercases the enum string and writes it to the XML node:
    value.ToString().ToLower(CultureInfo.InvariantCulture) => Writes "in", "out", or "none" into the XML.
  2. Read (Getter): The getter reads the raw string (e.g. "in") but parses it case-sensitively back to the eAxisTickMark enum (which expects capitalized members: In, Out, None, Cross):
    return (eAxisTickMark)Enum.Parse(typeof(eAxisTickMark), v);
  3. The Consequence: Because "in" does not match "In" case-sensitively, Enum.Parse throws an exception, catches it, and always falls back to returning the default Cross.

This makes it impossible to read back any value set on MajorTickMark or MinorTickMark unless it is Cross.

Proposed fix

Update Enum.Parse inside ExcelChartAxisStandard.cs's MajorTickMark and MinorTickMark properties to be case-insensitive by passing true as the third parameter:

// MajorTickMark Getter
return (eAxisTickMark)Enum.Parse(typeof(eAxisTickMark), v, true);

// MinorTickMark Getter
return (eAxisTickMark)Enum.Parse(typeof(eAxisTickMark), v, true);

This brings these properties into alignment with all other enum parsing calls inside ExcelChartAxisStandard.cs (which already use true for case-insensitivity, e.g., eTickLabelPosition, eCrosses, eCrossBetween, etc.).

PR ready for review/merge.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions