Merge pull request #23337 from axiac/fix-entity-search-with-long-keys
fix(catalog-backend): ignore long key paths when building entity search
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-backend': patch
|
||||
---
|
||||
|
||||
Do not fail on stitching when the entity contains `null` values associated to deeply nested or long keys.
|
||||
@@ -111,7 +111,14 @@ describe('buildEntitySearch', () => {
|
||||
});
|
||||
|
||||
it('skips very large keys', () => {
|
||||
const input = [{ key: 'a'.repeat(10000), value: 'foo' }];
|
||||
const input = [
|
||||
{ key: 'a'.repeat(10000), value: true },
|
||||
{ key: 'b'.repeat(10000), value: false },
|
||||
{ key: 'c'.repeat(10000), value: 7 },
|
||||
{ key: 'd'.repeat(10000), value: 'foo' },
|
||||
{ key: 'e'.repeat(10000), value: null },
|
||||
{ key: 'f'.repeat(10000), value: undefined },
|
||||
];
|
||||
const output = mapToRows(input, 'eid');
|
||||
expect(output).toEqual([]);
|
||||
});
|
||||
|
||||
@@ -133,6 +133,9 @@ export function mapToRows(input: Kv[], entityId: string): DbSearchRow[] {
|
||||
|
||||
for (const { key: rawKey, value: rawValue } of input) {
|
||||
const key = rawKey.toLocaleLowerCase('en-US');
|
||||
if (key.length > MAX_KEY_LENGTH) {
|
||||
continue;
|
||||
}
|
||||
if (rawValue === undefined || rawValue === null) {
|
||||
result.push({
|
||||
entity_id: entityId,
|
||||
@@ -142,22 +145,20 @@ export function mapToRows(input: Kv[], entityId: string): DbSearchRow[] {
|
||||
});
|
||||
} else {
|
||||
const value = String(rawValue).toLocaleLowerCase('en-US');
|
||||
if (key.length <= MAX_KEY_LENGTH) {
|
||||
if (value.length <= MAX_VALUE_LENGTH) {
|
||||
result.push({
|
||||
entity_id: entityId,
|
||||
key,
|
||||
original_value: String(rawValue),
|
||||
value: value,
|
||||
});
|
||||
} else {
|
||||
result.push({
|
||||
entity_id: entityId,
|
||||
key,
|
||||
original_value: null,
|
||||
value: null,
|
||||
});
|
||||
}
|
||||
if (value.length <= MAX_VALUE_LENGTH) {
|
||||
result.push({
|
||||
entity_id: entityId,
|
||||
key,
|
||||
original_value: String(rawValue),
|
||||
value: value,
|
||||
});
|
||||
} else {
|
||||
result.push({
|
||||
entity_id: entityId,
|
||||
key,
|
||||
original_value: null,
|
||||
value: null,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user