Skip to content

Commit

Permalink
Merge branch 'master' into UIU-2993
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-blazhko authored Nov 9, 2023
2 parents 46a869f + 27c788e commit da3641f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Correctly handle optional `X-Okapi-token` request header. Refs UIU-2977.
* Fix bug with Edit form Expand/collapse all shortcuts not working. Refs UIU-2959.
* Update patron groups retrieval in user search to hold `maxUnpagedResourceCount`. Refs UIU-2973.
* Update resourceData and queryParams in `UserSearchContainer.js` to escape special characters in tags filter. Refs. UIU-2995.
* Lost item fees not suspended when item is claimed returned from the ellipses in action menu. Refs UIU-2993.

## [10.0.3](https://github.com/folio-org/ui-users/tree/v10.0.3) (2023-10-23)
Expand Down
34 changes: 33 additions & 1 deletion src/routes/UserSearchContainer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import {
cloneDeep,
get,
template,
} from 'lodash';
Expand Down Expand Up @@ -34,8 +35,39 @@ const searchFields = [
];
const compileQuery = template(`(${searchFields.join(' or ')})`, { interpolate: /%{([\s\S]+?)}/g });

/*
Some of the special characters that are allowed while creating a tag are "", \, *, ?
These special characters cause CQL exceptions while searching the user records, which are
assigned with such tags.
This function "escapeSpecialCharactersInTagFilters" intends to escape the special characters
in filters of type "Tags"
Ref: https://issues.folio.org/browse/UIU-2995
*/

const escapeSpecialCharactersInTagFilters = (queryParams, resourceData) => {
const newResourceData = cloneDeep(resourceData);
let escapedFilters;

if (resourceData.query.filters) {
const filterArr = resourceData.query.filters.split(',');
escapedFilters = filterArr.map(f => {
let newF = f;
if (f.startsWith('tags.')) {
newF = f.replace(/["^*?\\]/g, c => '\\' + c);
}
return newF;
});
escapedFilters = escapedFilters.join(',');

newResourceData.query.filters = escapedFilters;
queryParams.filters = escapedFilters;
}
return newResourceData;
};

export function buildQuery(queryParams, pathComponents, resourceData, logger, props) {
const customFilterConfig = buildFilterConfig(queryParams.filters);
const newResourceData = escapeSpecialCharactersInTagFilters(queryParams, resourceData);

return makeQueryFunction(
'cql.allRecords=1',
Expand All @@ -53,7 +85,7 @@ export function buildQuery(queryParams, pathComponents, resourceData, logger, pr
},
[...filterConfig, ...customFilterConfig],
2,
)(queryParams, pathComponents, resourceData, logger, props);
)(queryParams, pathComponents, newResourceData, logger, props);
}

class UserSearchContainer extends React.Component {
Expand Down

0 comments on commit da3641f

Please sign in to comment.