pjfanning opened a new pull request, #1326:
URL: https://github.com/apache/poi/pull/1326

   Fixes https://bz.apache.org/bugzilla/show_bug.cgi?id=69878
   
   The reporter's analysis is correct: `Countif.getWildCardPattern` translates 
an Excel wildcard criteria into a java regex and escaped only `. $ ^ [ ] ( )`. 
`+`, `\`, `|`, `{` and `}` were passed through as regex syntax, so 
`COUNTIF(A1:A1,"A+B*")` counted 0 for a cell containing `A+B*` (`A+` = one or 
more `A`), and `"\*Foo+Bar*"` produced the regex `\.*Foo+Bar.*`. The same code 
serves SUMIF, AVERAGEIF and the `*IFS` functions.
   
   ### Fix
   - Escape every character with a special regex meaning (`\ ^ $ . | + ( ) [ ] 
{ }`) instead of the partial list.
   - Excel's escape character `~` applies to `?`, `*` **and `~`** (Microsoft's 
wildcard documentation: "~ followed by ?, *, or ~ — a question mark, asterisk, 
or tilde"). POI handled `~?` and `~*` but read `a~~*` as "a" + literal `*` 
preceded by a stray `~`; `~~` is now a literal tilde, so `a~~*` matches `a~xyz`.
   
   Criteria without `?`/`*` are unaffected — they never went through the regex 
path.
   
   ### Tests (`TestCountFuncs`)
   - `testWildCardsWithRegexMetaCharacters`: the reporter's two criteria, a 
loop over every metacharacter, and `[a-z]*`, `a{2}*`, `a|b*` as literals.
   - `testEscapedTilde`: `a~~*` and `a~~~*`.
   - `testWildCardsWithRegexMetaCharactersInWorkbook`: the reporter's 
reproduction steps (`="A+B*"` in A1, `COUNTIF(A1:A1,"A+B*")` = 1), also via 
SUMIF and COUNTIFS.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to