Skip to content

Commit

Permalink
Merge pull request #933 from koopjs/p/where-replacer
Browse files Browse the repository at this point in the history
Handle "where" param with +
  • Loading branch information
rgwozdz authored Feb 27, 2024
2 parents 937b496 + bf48f36 commit f102155
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 97 deletions.
5 changes: 5 additions & 0 deletions .changeset/three-actors-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@koopjs/featureserver": patch
---

- allow + as whitespace equivalent in where param
8 changes: 4 additions & 4 deletions packages/featureserver/coverage-unit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 31 additions & 7 deletions packages/featureserver/src/query/filter-and-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ class FilterAndTransformParams {
}

static standardize (requestParams) {
const {returnDistinctValues, ...rest } = requestParams;
const {returnDistinctValues, where = '1=1', ...rest } = requestParams;

if (returnDistinctValues === true) {
rest.distinct = true;
}

return rest;
return {
...rest,
distinct: !!returnDistinctValues,
where: extractPlusPlaceHolders(where)
};
}

constructor (requestParams) {
Expand Down Expand Up @@ -64,12 +64,36 @@ class FilterAndTransformParams {
return this;
}

addInputCrs (data = {}) {
addInputCrs (data) {
const { metadata = {} } = data;
this.inputCrs = this.inputCrs || this.sourceSR || metadata.crs || helpers.getCollectionCrs(data) || 4326;
delete this.sourceSR;
return this;
}
}

function extractPlusPlaceHolders(where) {
let openDouble = false;
let openSingle = false;
const whereWithReplacedSingleQuotes = where.replace(/''/g, '~~xxx~~');

const charArray = Array.from(whereWithReplacedSingleQuotes);
return charArray
.map((char) => {
if (char === '\'' && !openDouble) {
openSingle = !openSingle;
}

if (char === '"' && !openSingle) {
openDouble = !openDouble;
}

if (char === '+' && !openDouble && !openSingle) {
return ' ';
}
return char;
})
.join('')
.replace(/~~xxx~~/g, '\'\'');
}
module.exports = { filterAndTransform };
Loading

0 comments on commit f102155

Please sign in to comment.