Skip to content

Commit d2c1afb

Browse files
committed
npm/firmware: drop default fallback in encodeHubName()
Technically, and empty name is valid according to the Bluetooth spec and the firmware already includes a default that might not be this, so it best to handle the empty string case before calling this function if we want the empty string to mean "use the default value".
1 parent aecba33 commit d2c1afb

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

npm/firmware/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11

2+
## Unreleased
3+
### Changed
4+
- Dropped fallback to default name in `encodeHubName()` on empty string.
5+
26
## 4.13.0-rc.1 - 2021-11-19
37
### Added
48
- Added support for v1.1.0 metadata.

npm/firmware/index.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,9 @@ test('reading data works', async () => {
9494
describe('firmware name encoder', () => {
9595
const metadata = { 'max-hub-name-size': 16 } as FirmwareMetadata;
9696

97-
test('default works', () => {
97+
test('empty name works', () => {
9898
expect(encodeHubName('', metadata)).toEqual(
99-
new Uint8Array([
100-
80, 121, 98, 114, 105, 99, 107, 115, 32, 72, 117, 98, 0, 0, 0,
101-
0,
102-
])
99+
new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
103100
);
104101
});
105102

npm/firmware/index.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,6 @@ export function encodeHubName(
246246
throw new Error('firmware image does not support firmware name');
247247
}
248248

249-
// fall back to default on empty name
250-
if (!name) {
251-
name = 'Pybricks Hub';
252-
}
253-
254249
const bytes = new Uint8Array(metadata['max-hub-name-size']);
255250

256251
// subarray ensures zero termination if encoded length is >= 'max-hub-name-size'.

0 commit comments

Comments
 (0)