fix: wrap in square brackets if needed (#1171)

This commit is contained in:
Tobias Linsefors
2023-03-21 15:03:45 +01:00
committed by GitHub
parent 48736a8684
commit f49e4e2ec3
2 changed files with 13 additions and 1 deletions

View File

@@ -0,0 +1,9 @@
import { getFrequencyMaxExpression } from '../frequencyMaxUtil';
describe('frequencyMaxUtil - getFrequencyMaxExpression', () => {
test('should create correct expression and wrap and escape field if needed', async () => {
const result = getFrequencyMaxExpression('dimension with ] in it');
expect(result).toEqual('Max(AGGR(Count([dimension with ]] in it]), [dimension with ]] in it]))');
});
});

View File

@@ -2,7 +2,10 @@ const escapeField = (field) => {
if (!field) {
return field;
}
return `${field.replace(/\]/g, ']]')}`;
if (/^[A-Za-z][A-Za-z0-9_]*$/.test(field)) {
return field;
}
return `[${field.replace(/\]/g, ']]')}]`;
};
export const needToFetchFrequencyMax = (layout) => layout?.frequencyMax === 'fetch';