From 1388b60e5542d4c8ba6de373d5c9026976d84917 Mon Sep 17 00:00:00 2001 From: sedinkinya Date: Thu, 25 Apr 2024 17:48:07 -0400 Subject: [PATCH 1/2] Enabled unicode-aware mode for regular expressions in fhirpath LF-3015 --- CHANGELOG.md | 5 +++++ package-lock.json | 4 ++-- package.json | 2 +- src/strings.js | 6 +++--- test/cases/5.6_string_manipulation.yaml | 8 ++++++++ 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ddf3ea..0b593c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ 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 `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])`. diff --git a/package-lock.json b/package-lock.json index 016e682..647100a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "fhirpath", - "version": "3.13.0", + "version": "3.13.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "fhirpath", - "version": "3.13.0", + "version": "3.13.1", "license": "SEE LICENSE in LICENSE.md", "dependencies": { "@lhncbc/ucum-lhc": "^5.0.0", diff --git a/package.json b/package.json index e241ca4..9063331 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fhirpath", - "version": "3.13.0", + "version": "3.13.1", "description": "A FHIRPath engine", "main": "src/fhirpath.js", "dependencies": { diff --git a/src/strings.js b/src/strings.js index 24ab343..5232ec0 100644 --- a/src/strings.js +++ b/src/strings.js @@ -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 { @@ -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); }; } @@ -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); }; diff --git a/test/cases/5.6_string_manipulation.yaml b/test/cases/5.6_string_manipulation.yaml index 74936df..2533de9 100644 --- a/test/cases/5.6_string_manipulation.yaml +++ b/test/cases/5.6_string_manipulation.yaml @@ -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: @@ -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' From 11a1840d69283f18a77cac4bbfa1c478c34e5fa5 Mon Sep 17 00:00:00 2001 From: sedinkinya Date: Thu, 2 May 2024 15:09:57 -0400 Subject: [PATCH 2/2] Changes as per review LF-3015 --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b593c6..d66664d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,9 @@ This log documents significant changes for each release. This project follows ## [3.13.1] - 2024-04-25 ### Fixed -- Added flag 'u' for regular expressions in the `matches` and `replaceMatches` - functions to support the use of unicode character class escapes. +- 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