Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…rafana-datasource into v4-deploy
  • Loading branch information
SpencerTorres committed Jan 22, 2024
2 parents e9f8b5c + 93a0620 commit 38c92d6
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/data/sqlGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ const escapeIdentifier = (id: string): string => {
}

const escapeValue = (value: string): string => {
if (value.includes('(') || value.includes(')') || value.includes('"') || value.includes('"')) {
if (value.includes('$') || value.includes('(') || value.includes(')') || value.includes('\'') || value.includes('"')) {
return value;
}

Expand Down Expand Up @@ -695,12 +695,12 @@ const getFilters = (options: QueryBuilderOptions): string => {
if (filter.operator === FilterOperator.Like || filter.operator === FilterOperator.NotLike) {
filterParts.push(`'%${filter.value || ''}%'`);
} else {
filterParts.push(formatStringValue((filter as StringFilter).value || ''));
filterParts.push(escapeValue((filter as StringFilter).value || ''));
}
} else if (isMultiFilter(type, filter.operator)) {
filterParts.push(`(${(filter as MultiFilter).value?.map(v => formatStringValue(v)).join(', ')})`);
filterParts.push(`(${(filter as MultiFilter).value?.map(v => escapeValue(v)).join(', ')})`);
} else {
filterParts.push(formatStringValue((filter as StringFilter).value || ''));
filterParts.push(escapeValue((filter as StringFilter).value || ''));
}

if (negate) {
Expand Down Expand Up @@ -734,7 +734,6 @@ const isDateFilterWithoutValue = (type: string, operator: FilterOperator): boole
const isDateFilter = (type: string): boolean => isDateType(type);
const isStringFilter = (type: string, operator: FilterOperator): boolean => isStringType(type) && !(operator === FilterOperator.In || operator === FilterOperator.NotIn);
const isMultiFilter = (type: string, operator: FilterOperator): boolean => isStringType(type) && (operator === FilterOperator.In || operator === FilterOperator.NotIn);
const formatStringValue = (filter: string): string => filter.startsWith('$') ? (filter || '') : `'${filter || ''}'`;

/**
* When filtering in the logs panel in explore view, we need a way to
Expand Down

0 comments on commit 38c92d6

Please sign in to comment.