Skip to content

Commit

Permalink
Merge pull request #249 from usnistgov/fix/ODD937-wrong-search-url
Browse files Browse the repository at this point in the history
Fixed a bug when dealing with quotes
  • Loading branch information
deoyani authored Nov 10, 2020
2 parents 673834a + 7b9735e commit df1398b
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions angular/src/app/shared/search-query/search-query.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ export class SearchQueryService {
buildQueryFromString(queryString: string, queryName?: string, fields?: SelectItem[]): SDPQuery{
//Trim spaces
queryString = queryString.replace(/\s+/g, ' ');

let lQueryName: string;
//We are not going to save empty string
if(!queryString){
Expand All @@ -239,15 +238,15 @@ export class SearchQueryService {

//Reserve everything in quotes
let quotes = queryString.match(/\"(.*?)\"/g);

if(quotes){
for(let i = 0; i < quotes.length; i++){
if(quotes[i] != '""')
queryString = queryString.replace(new RegExp(quotes[i].match(/\"(.*?)\"/)[1], 'g'), 'Quooooote'+("000" + i).slice(-3));
queryString = queryString.replace(new RegExp('"' + quotes[i].match(/\"(.*?)\"/)[1] + '"', 'g'), 'Quooooote'+("000" + i).slice(-3));
}
}

let queryStringObject = this.parseQueryString(queryString);

//Restore everything in quotes to free text string
if(quotes){
for(let i = 0; i < quotes.length; i++){
Expand All @@ -261,7 +260,6 @@ export class SearchQueryService {
let lKeyValuePair: string = queryStringObject.keyValuePairString;
let query: SDPQuery = new SDPQuery(this.nextQueryId(), lQueryName);
query.freeText = lFreeTextSearch.trim();

if(!this.isEmpty(lKeyValuePair)){

lKeyValuePair = lKeyValuePair.replace(new RegExp(' AND ', 'g'), '&AND&');
Expand Down Expand Up @@ -308,7 +306,7 @@ export class SearchQueryService {
if(quotes){
for(let i = 0; i < quotes.length; i++){
if(quotes[i] != '""'){
row.fieldText = row.fieldText.replace(new RegExp('Quooooote'+("000" + i).slice(-3), 'g'), quotes[i].match(/\"(.*?)\"/)[1]);
row.fieldText = row.fieldText.replace(new RegExp('Quooooote'+("000" + i).slice(-3), 'g'), '"'+quotes[i].match(/\"(.*?)\"/)[1]+'"');
}
}
}
Expand Down

0 comments on commit df1398b

Please sign in to comment.