Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: escape characters in clickhouse query params #1294

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
coerceFilterValues,
fillColumnMetaData,
CoercedFilterValues,
escapeStringsFromParams,
} from './util.js';

/**
Expand Down Expand Up @@ -721,6 +722,8 @@ export class AnalyticsRequestViewRepository {

whereSql += scopedSql;

escapeStringsFromParams(coercedQueryParams);

const [result, totalCount] = await Promise.all([
this.getViewData(name, whereSql, havingSql, paginationSql, coercedQueryParams, orderSql),
this.getTotalCount(name, whereSql, havingSql, coercedQueryParams),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
buildCoercedFilterSqlStatement,
CoercedFilterValues,
coerceFilterValues,
escapeStringsFromParams,
getDateRange,
getGranularity,
isoDateRangeToTimestamps,
Expand Down Expand Up @@ -526,6 +527,8 @@ export class MetricsRepository {

const { whereSql } = buildCoercedFilterSqlStatement({}, coercedFilters.result, coercedFilters.filterMapper, false);

escapeStringsFromParams(coercedFilters.result);

return {
granule,
rangeInHours: diff,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
buildCoercedFilterSqlStatement,
CoercedFilterValues,
coerceFilterValues,
escapeStringsFromParams,
getDateRange,
getGranularity,
isoDateRangeToTimestamps,
Expand Down Expand Up @@ -546,6 +547,8 @@ export class SubgraphMetricsRepository {

const { whereSql } = buildCoercedFilterSqlStatement({}, coercedFilters.result, coercedFilters.filterMapper, false);

escapeStringsFromParams(coercedFilters.result);

return {
granule,
rangeInHours: diff,
Expand Down
10 changes: 10 additions & 0 deletions controlplane/src/core/repositories/analytics/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,3 +465,13 @@ export const parseValue = (value?: string | number | null) => {
}
return value || '0';
};

export const escapeStringsFromParams = (obj: { [key: string]: any }) => {
for (const key in obj) {
if (typeof obj[key] === 'string') {
obj[key] = obj[key]
.replace(/\n/g, '\\n') // new lines
.replace(/\t/g, '\\t'); // tabs
}
}
};
Loading