Skip to content

Commit

Permalink
Merge pull request #21 in LFOR/fhirpath.js from bugfix/LF-1606/undefi…
Browse files Browse the repository at this point in the history
…ned-variables to master

* commit 'eac78a13135769e8cdca63489940fce0ee82007e':
  null value in environment variable is treated as empty
  Environment variable missing check changed
  Fix handling of undefined variables
  Bump websocket-extensions from 0.1.3 to 0.1.4 in /demo
  • Loading branch information
yuriy-sedinkin committed Nov 2, 2020
2 parents f372723 + eac78a1 commit d477689
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
This log documents significant changes for each release. This project follows
[Semantic Versioning](http://semver.org/).

## [2.7.1] - 2020-10-29
### Fixed
- Now, attempting to access an undefined environment variable will result
in an error

## [2.7.0] - 2020-10-21
### Added
- Evaluating expression for a part of a resource
Expand Down
6 changes: 3 additions & 3 deletions demo/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-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": "2.7.0",
"version": "2.7.1",
"description": "A FHIRPath engine",
"main": "src/fhirpath.js",
"dependencies": {
Expand Down
9 changes: 8 additions & 1 deletion src/fhirpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,16 @@ engine.ExternalConstantTerm = function(ctx, parentData, node) {
var identifier = extConstant.children[0];
var varName = engine.Identifier(ctx, parentData, identifier)[0];
var value = ctx.vars[varName];
if (!(varName in ctx.vars)) {
throw new Error(
"Attempting to access an undefined environment variable: " + varName
);
}
// For convenience, we all variable values to be passed in without their array
// wrapper. However, when evaluating, we need to put the array back in.
return value === undefined ? [] : value instanceof Array ? value : [value];
return value === undefined || value === null
? []
: value instanceof Array ? value : [value];
};

engine.LiteralTerm = function(ctx, parentData, node) {
Expand Down
13 changes: 13 additions & 0 deletions test/cases/8_variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ tests:
variables:
a: 5
result: [4]
- desc: 'Empty variable'
expression: '%a'
variables:
a: []
result: []
- desc: 'Null variable'
expression: '%a'
variables:
a: null
result: []
- desc: 'Undefined variable'
expression: '%a'
error: true
- desc: 'Escaped variables'
expression: '%`a.b() - 1` - 2'
variables:
Expand Down

0 comments on commit d477689

Please sign in to comment.