Skip to content

Commit

Permalink
Merge branch 'bugfix/LF-3015/enable-unicode-aware-mode-for-regular-ex…
Browse files Browse the repository at this point in the history
…pressions' into 'master'

Enabled unicode-aware mode for regular expressions in fhirpath

See merge request lfor/fhirpath.js!13
  • Loading branch information
yuriy-sedinkin committed May 6, 2024
2 parents 284ca22 + 11a1840 commit e0fe2b5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
This log documents significant changes for each release. This project follows
[Semantic Versioning](http://semver.org/).

## [3.13.1] - 2024-04-25
### Fixed
- Added flag 'u' for regular expressions in the specification's `matches` and
`replaceMatches` functions to support the use of unicode character class
escapes.

## [3.13.0] - 2024-04-10
### Added
- Function `defineVariable(name: String [, expr: expression])`.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fhirpath",
"version": "3.13.0",
"version": "3.13.1",
"description": "A FHIRPath engine",
"main": "src/fhirpath.js",
"dependencies": {
Expand Down
6 changes: 3 additions & 3 deletions src/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ if (dotAllIsSupported) {
if (util.isEmpty(regex) || util.isEmpty(str)) {
return [];
}
const reg = new RegExp(regex, 's');
const reg = new RegExp(regex, 'su');
return reg.test(str);
};
} else {
Expand All @@ -171,7 +171,7 @@ if (dotAllIsSupported) {
if (util.isEmpty(regex) || util.isEmpty(str)) {
return [];
}
const reg = new RegExp(rewritePatternForDotAll(regex));
const reg = new RegExp(rewritePatternForDotAll(regex), 'u');
return reg.test(str);
};
}
Expand All @@ -190,7 +190,7 @@ engine.replaceMatches = function (coll, regex, repl) {
if (util.isEmpty(regex) || util.isEmpty(repl) || util.isEmpty(str)) {
return [];
}
const reg = new RegExp(regex, 'g');
const reg = new RegExp(regex, 'gu');
return str.replace(reg, repl);
};

Expand Down
8 changes: 8 additions & 0 deletions test/cases/5.6_string_manipulation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ tests:
expression: Patient.name.given[0].matches('.*')
result: []

- desc: '** matches with unicode character class escapes'
expression: "'Taupō'.matches('^\\\\p{Lu}\\\\p{Ll}*$')"
result: [true]

- desc: '5.6.10. replaceMatches(regex : string, substitution: string) : string'
# If the input collection contains a single item of type string, the function will match the input using the regular expression in regex and replace each match with the substitution string. The substitution may refer to identified match groups in the regular expression.
# This example of replaceMatches() will convert a string with a date formatted as MM/dd/yy to dd-MM-yy:
Expand Down Expand Up @@ -299,6 +303,10 @@ tests:
expression: Patient.name.given[0].replaceMatches('(.*)', '$1')
result: []

- desc: '** replaceMatches with a unicode character class escape'
expression: "'Taupō'.replaceMatches('(\\\\p{Lu})', 'city: $1')"
result: ['city: Taupō']

- desc: '5.6.11. length() : integer'
# If the input collection contains a single item of type string, the function will return the length of the string. If the input collection is empty ({ }), the result is empty.
- desc: '** length'
Expand Down

0 comments on commit e0fe2b5

Please sign in to comment.