Skip to content

Commit

Permalink
Escape the last quotation mark when uneven number
Browse files Browse the repository at this point in the history
  • Loading branch information
ommann committed Mar 7, 2024
1 parent 3f4019b commit c93926b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -629,9 +629,6 @@ function splitFields(obj: Record<string, string | string[]>): Record<string, str
const result: Record<string, string[]> = {};

for (const key in obj) {
// console log key and value
// console.log(key, obj[key]);

if (key === 'q') {
result[key] = [obj[key] as string];
} else {
Expand Down
17 changes: 16 additions & 1 deletion src/app/portal/services/publication2.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,23 @@ export class Publication2Service {
}
}

function escapeLastQuoteIfOdd(inputString: string): string {
// Count the number of quotation marks in the string
const quoteCount = (inputString.match(/"/g) || []).length;

// If the count is odd, escape the last quotation mark
if (quoteCount % 2 !== 0) {
const lastQuoteIndex = inputString.lastIndexOf('"');
// Replace the last quotation mark with an escaped version
inputString = inputString.substring(0, lastQuoteIndex) + '\\"' + inputString.substring(lastQuoteIndex + 1);
}

return inputString;
}

function matchingTerms(searchParams: SearchParams) {
const q = (searchParams.q ?? [""])[0];
let q = (searchParams.q ?? [""])[0];
q = escapeLastQuoteIfOdd(q);

if (q === "") {
return {
Expand Down

0 comments on commit c93926b

Please sign in to comment.