InfluxQL: Quoting tag values in the query editor (#54187)

* Quote numeric values in query editor
This commit is contained in:
Galen Kistler 2022-08-26 08:26:44 -05:00 committed by GitHub
parent 26524e3ff1
commit 6ed0787376
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View File

@ -19,8 +19,9 @@ function renderTagCondition(tag: { operator: any; value: string; condition: any;
}
}
// quote value unless regex or number, or if empty-string
if (value === '' || (operator !== '=~' && operator !== '!~' && isNaN(+value))) {
// quote value unless regex or empty-string
// Influx versions before 0.13 had inconsistent requirements on if (numeric) tags are quoted or not.
if (value === '' || (operator !== '=~' && operator !== '!~')) {
value = "'" + value.replace(/\\/g, '\\\\').replace(/\'/g, "\\'") + "'";
}

View File

@ -166,7 +166,7 @@ describe('InfluxQueryBuilder', () => {
undefined
);
const query = builder.buildExploreQuery('MEASUREMENTS');
expect(query).toBe(`SHOW MEASUREMENTS WHERE "app" == 42 LIMIT 100`);
expect(query).toBe(`SHOW MEASUREMENTS WHERE "app" == '42' LIMIT 100`);
});
it('should handle tag-value=number-ish getting tag-keys', () => {
@ -175,7 +175,7 @@ describe('InfluxQueryBuilder', () => {
undefined
);
const query = builder.buildExploreQuery('TAG_KEYS');
expect(query).toBe(`SHOW TAG KEYS WHERE "app" == 42`);
expect(query).toBe(`SHOW TAG KEYS WHERE "app" == '42'`);
});
it('should handle tag-value-contains-backslash-character getting tag-keys', () => {