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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed
* Keep base64url padding when encoding object store names and digests, matching the reference implementation (nats.go `base64.URLEncoding`). Objects written by previous versions use unpadded meta subjects and must be re-put to be visible to the fixed client and to other NATS clients.

## [0.4.1] 2026-04-21

### Added
Expand Down
7 changes: 6 additions & 1 deletion src/JetStream/ObjectStore/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,13 @@ public function seal(): void
$this->js->updateStream($info->config->seal());
}

/**
* Padding must be kept: nats.go encodes object names in meta subjects and object
* digests with padded url-safe base64 (base64.URLEncoding) and rejects unpadded
* digests on read.
*/
private function base64encode(string $name): string
{
return rtrim(strtr(base64_encode($name), '+/', '-_'), '=');
return strtr(base64_encode($name), '+/', '-_');
}
}
6 changes: 6 additions & 0 deletions tests/JetStream/ObjectStore/ObjectStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ public function testPutObject(): void
self::assertSame(10, $info->size);
self::assertSame(1, $info->chunks);

// Padded url-safe base64, as written by nats.go (base64.URLEncoding).
self::assertSame(
'SHA-256=' . strtr(base64_encode(hash('sha256', $body, true)), '+/', '-_'),
$info->digest,
);

$object = $store->get('xfile');
self::assertSame($body, (string) $object);

Expand Down
Loading