Skip to content

Commit a6aa412

Browse files
committed
Reject blank or duplicate plugin names at registration
registerPlugin now throws when a plugin's name is empty or already registered, defaultResult reports the plugin's own name, and the changelog notes that custom plugins must set a unique name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PS44Q9PbJcTZqm3Ks4UNxW
1 parent 0d773aa commit a6aa412

4 files changed

Lines changed: 24 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
44

55
## Unreleased
66

7+
- `DecoderPluginInterface.name` is now required, and `MessageDecoder.registerPlugin` throws on a blank or duplicate plugin name. Custom plugins passed to `registerPlugin` must set a unique `name`.
8+
79
## 1.7.0
810

911
- Node.js support and CI:

‎lib/DecoderPlugin.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export abstract class DecoderPlugin implements DecoderPluginInterface {
1818
return {
1919
decoded: false,
2020
decoder: {
21-
name: 'unknown',
21+
name: this.name,
2222
type: 'pattern-match',
2323
decodeLevel: 'none',
2424
},

‎lib/MessageDecoder.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,20 @@ describe('MessageDecoder', () => {
257257
expect(result.decoded).toBe(false);
258258
});
259259

260+
test('registerPlugin rejects a blank plugin name', () => {
261+
const decoder = new MessageDecoder();
262+
expect(() =>
263+
decoder.registerPlugin(new StubPlugin(decoder, ' ', ['99'])),
264+
).toThrow('Decoder plugin name must be a non-empty string');
265+
});
266+
267+
test('registerPlugin rejects a duplicate plugin name', () => {
268+
const decoder = new MessageDecoder();
269+
expect(() =>
270+
decoder.registerPlugin(new StubPlugin(decoder, 'label-15', ['99'])),
271+
).toThrow('Duplicate decoder plugin name: label-15');
272+
});
273+
260274
test('registerPlugin adds to label index', () => {
261275
const decoder = new MessageDecoder();
262276
const stub = new StubPlugin(decoder, 'stub-99', ['99']);

‎lib/MessageDecoder.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ export class MessageDecoder {
124124
}
125125

126126
registerPlugin(plugin: DecoderPluginInterface): boolean {
127+
const name = typeof plugin.name === 'string' ? plugin.name.trim() : '';
128+
if (!name) {
129+
throw new Error('Decoder plugin name must be a non-empty string');
130+
}
131+
if (this.plugins.some((existing) => existing.name === name)) {
132+
throw new Error(`Duplicate decoder plugin name: ${name}`);
133+
}
127134
this.plugins.push(plugin);
128135

129136
const qualifiers = plugin.qualifiers();

0 commit comments

Comments
 (0)