Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions ui/src/utils/packetTypes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,37 @@ describe('formatPacketType', () => {
).toBe('Raw Video (*x*, Rgba8)');
});

it('does not render wildcard when template placeholder omits |*', () => {
setPacketTypeRegistry([
...DEFAULT_METAS,
{
id: 'TestNoStar',
label: 'Test',
color: '#000',
display_template: 'Test ({width}x{height|*})',
compatibility: {
kind: 'structfieldwildcard',
fields: [
{ name: 'width', wildcard_value: null },
{ name: 'height', wildcard_value: null },
],
},
},
]);
const result = formatPacketType({
TestNoStar: { width: null, height: null },
} as unknown as PacketType);
expect(result).toBe('Test (nullx*)');
});

it('renders literal value for plain placeholder even when it matches wildcard_value', () => {
expect(
formatPacketType({
RawVideo: { width: 1920, height: 1080, pixel_format: null },
} as unknown as PacketType)
).toBe('Raw Video (1920x1080, null)');
});

it('renders the Custom template with the supplied type_id', () => {
expect(formatPacketType({ Custom: { type_id: 'my.custom.type' } })).toBe(
'Custom (my.custom.type)'
Expand Down
4 changes: 2 additions & 2 deletions ui/src/utils/packetTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ function formatWithTemplate(
payload: Record<string, unknown> | undefined,
compat?: Compatibility
): string {
return template.replace(/\{(\w+)(\|\*)?\}/g, (_m, field: string) => {
return template.replace(/\{(\w+)(\|\*)?\}/g, (_m, field: string, star?: string) => {
const value = (payload as Record<string, unknown> | undefined)?.[field];
let isWildcard = false;
if (compat && compat.kind === 'structfieldwildcard') {
if (compat && compat.kind === 'structfieldwildcard' && star) {
const rule = compat.fields.find((f) => f.name === field);
if (rule && 'wildcard_value' in rule) {
isWildcard = deepEqual(value, rule.wildcard_value);
Expand Down
Loading