https://bz.apache.org/bugzilla/show_bug.cgi?id=69878

            Bug ID: 69878
           Summary: COUNTIF pattern matching not escaping +, \
           Product: POI
           Version: 5.4.0-FINAL
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XSSF
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ---

Created attachment 40126
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=40126&action=edit
File where Excel correctly counts 1 match, but POI counts 0 matches.

*Overview.* In Countif.java, the getWildCardPattern method attempts to escape 
symbols with special meaning in regular expressions. However, it does not
escape + or \.

So for example, when evaluating COUNTIF(A1:A10, "\*Foo+Bar*"), the regular
expression for the criteria becomes "\*Foo+Bar*", but should be
"[\]*Foo[+]Bar*" or "\\*Foo\+Bar*".

Note that this bug does not occur when there is no "*" or "?" in the match
criteria, since POI does not match using regular expressions otherwise.


*Steps to reproduce.* 1) Set up an xlsx sheet A1 containing `="A+B*"` and B1
containing  the formula `=COUNTIF(A1:A1, "A+B*")`. 2) Evaluate the sheet using
POI and read the value of B1. (I use `DataFormatter.formatCellValue(cell,
evaluator)`)


*Actual results.* The cell is evaluated to 0 (i.e. does not find a match).


*Expected results.* The cell is evaluated to 1 (i.e. does find a match).


*Build date and hardware.* Build 2025-11-05 (November 5, 2025) on Google
Kubernetes Engine (Docker image jetty:9.4.57-jdk17). 


*Additional builds and platforms.* Also verified on Mac OS 14.6.1, but the
cause of the bug is independent of platform and hardware.


*Additional information.* There may be additional regular expression symbols
which should be escaped. For example, "{" does not look to be escaped, but I
have not verified that this is an issue.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to