Skip adding entries to the entities_search table if their key exceeds a length limit.
Signed-off-by: Dominik Henneke <dominik.henneke@sda-se.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-backend': patch
|
||||
---
|
||||
|
||||
Skip adding entries to the `entities_search` table if their `key` exceeds a length limit.
|
||||
@@ -101,6 +101,12 @@ describe('search', () => {
|
||||
expect(output).toEqual([{ entity_id: 'eid', key: 'foo', value: 'bar' }]);
|
||||
});
|
||||
|
||||
it('skips very large keys', () => {
|
||||
const input = [{ key: 'a'.repeat(10000), value: 'foo' }];
|
||||
const output = mapToRows(input, 'eid');
|
||||
expect(output).toEqual([]);
|
||||
});
|
||||
|
||||
it('skips very large values', () => {
|
||||
const input = [{ key: 'foo', value: 'a'.repeat(10000) }];
|
||||
const output = mapToRows(input, 'eid');
|
||||
|
||||
@@ -31,6 +31,7 @@ const SPECIAL_KEYS = [
|
||||
// The maximum length allowed for search values. These columns are indexed, and
|
||||
// database engines do not like to index on massive values. For example,
|
||||
// postgres will balk after 8191 byte line sizes.
|
||||
const MAX_KEY_LENGTH = 200;
|
||||
const MAX_VALUE_LENGTH = 200;
|
||||
|
||||
type Kv = {
|
||||
@@ -136,7 +137,7 @@ export function mapToRows(
|
||||
result.push({ entity_id: entityId, key, value: null });
|
||||
} else {
|
||||
const value = String(rawValue).toLowerCase();
|
||||
if (value.length <= MAX_VALUE_LENGTH) {
|
||||
if (key.length <= MAX_KEY_LENGTH && value.length <= MAX_VALUE_LENGTH) {
|
||||
result.push({ entity_id: entityId, key, value });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,6 +104,12 @@ describe('search', () => {
|
||||
expect(output).toEqual([{ entity_id: 'eid', key: 'foo', value: 'bar' }]);
|
||||
});
|
||||
|
||||
it('skips very large keys', () => {
|
||||
const input = [{ key: 'a'.repeat(10000), value: 'foo' }];
|
||||
const output = mapToRows(input, 'eid');
|
||||
expect(output).toEqual([]);
|
||||
});
|
||||
|
||||
it('skips very large values', () => {
|
||||
const input = [{ key: 'foo', value: 'a'.repeat(10000) }];
|
||||
const output = mapToRows(input, 'eid');
|
||||
|
||||
@@ -43,6 +43,7 @@ const SPECIAL_KEYS = [
|
||||
// The maximum length allowed for search values. These columns are indexed, and
|
||||
// database engines do not like to index on massive values. For example,
|
||||
// postgres will balk after 8191 byte line sizes.
|
||||
const MAX_KEY_LENGTH = 200;
|
||||
const MAX_VALUE_LENGTH = 200;
|
||||
|
||||
type Kv = {
|
||||
@@ -145,7 +146,7 @@ export function mapToRows(input: Kv[], entityId: string): DbSearchRow[] {
|
||||
result.push({ entity_id: entityId, key, value: null });
|
||||
} else {
|
||||
const value = String(rawValue).toLocaleLowerCase('en-US');
|
||||
if (value.length <= MAX_VALUE_LENGTH) {
|
||||
if (key.length <= MAX_KEY_LENGTH && value.length <= MAX_VALUE_LENGTH) {
|
||||
result.push({ entity_id: entityId, key, value });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user