nHapiNET / nHapi

nHapi is the .Net port of the original Java project HAPI.
Mozilla Public License 2.0
277 stars 156 forks source link

Fix Terser Regex bug Fixes #319 #340

Closed milkshakeuk closed 2 years ago

milkshakeuk commented 2 years ago

Looks like its always been a bug in nHapi due to the miss understanding of how regex in java vs C#, see below for a brief description of the difference.

The following in java...

Pattern.matches(pattern, candidate);

does not behave the same as the following in C#:

Regex.IsMatch(candidate, pattern);

in java the regular expression pattern must evaluate to a match on the entire candidate where as in C# the regular expression pattern must evaluate to a match within the candidate.

Pattern.matches("DIET", "TIMING_DIET"); // evaluates to false, because the pattern 'DIET' does not match 'TIMING_DIET'
Regex.IsMatch("TIMING_DIET", "DIET"); // evaluates to true, because the pattern 'DIET' has a match within 'TIMING_DIET'

This is what causes the bug described in #319

github-actions[bot] commented 2 years ago

Unit Test Results

       5 files         5 suites   19s :stopwatch: 1 150 tests 1 062 :heavy_check_mark:   88 :zzz: 0 :x: 2 134 runs  2 030 :heavy_check_mark: 104 :zzz: 0 :x:

Results for commit d9242ab3.

:recycle: This comment has been updated with latest results.

milkshakeuk commented 2 years ago

@AMCN41R if you get chance could you have a quick look at this?