Skip to content

Commit

Permalink
fix: prevent $search queries from throwing
Browse files Browse the repository at this point in the history
  • Loading branch information
BobdenOs committed Aug 5, 2024
1 parent ac58f9a commit c5f2de8
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions db-service/lib/cql-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@ const StandardFunctions = {
search: function (ref, arg) {
if (!('val' in arg)) throw new Error(`Only single value arguments are allowed for $search`)
// only apply first search term, rest is ignored
const sub= /("")|("(?:[^"]|\\")*(?:[^\\]|\\\\)")|(\S*)/.exec(arg.val)
arg.val = arg.__proto__.val = (sub[2] ? JSON.parse(sub[2]) : sub[3]) || ''
const refs = ref.list || [ref],
{ toString } = ref
const sub = /("")|("(?:[^"]|\\")*(?:[^\\]|\\\\)")|(\S*)/.exec(arg.val)
let val
try {
val = (sub[2] ? JSON.parse(sub[2]) : sub[3]) || ''
} catch {
val = sub[2] || sub[3] || ''
}
arg.val = arg.__proto__.val = val
const refs = ref.list || [ref]
const { toString } = ref
return '(' + refs.map(ref2 => this.contains(this.tolower(toString(ref2)), this.tolower(arg))).join(' or ') + ')'
},
/**
Expand Down Expand Up @@ -159,8 +165,8 @@ const StandardFunctions = {
* Generates SQL statement that produces current point in time (date and time with time zone)
* @returns {string}
*/
now: function() {
return this.session_context({val: '$now'})
now: function () {
return this.session_context({ val: '$now' })
},
/**
* Generates SQL statement that produces the year of a given timestamp
Expand Down

0 comments on commit c5f2de8

Please sign in to comment.