Skip to content

fix: match the server's NATS subject encoding for segments with dots - #11

Merged
sujal-maheshwari2004 merged 1 commit into
mainfrom
fix/10-subject-encoding
Oct 18, 2026
Merged

sujal-maheshwari2004 merged 1 commit into
mainfrom
fix/10-subject-encoding

Conversation

@sujal-maheshwari2004

Copy link
Copy Markdown
Contributor

What was wrong

priompt/priompt#33 changes the server's URI-to-subject mapping. Each URI segment becomes one subject token, and every byte outside [A-Za-z0-9_-] is percent-encoded with uppercase hex (. becomes %2E). _subject() only replaced / with ., so for a URI with a dot in a segment, subscribe() listened on a subject the server no longer publishes to, and hot reload got no events.

Fix

_subject() now ports pubsub.Subject / subjectToken from #33: split on /, then encode each segment's UTF-8 bytes. Dot-free URIs map exactly as before.

Tests

  • New test_subject cases: priompt://acme.corp/x/a.b maps to priompt.acme%2Ecorp.x.a%2Eb, and agent-v2_x stays unchanged. Wildcard bytes and UTF-8 are encoded too.
  • New test_subject_is_injective uses the server's own collision pairs from TestSubjectIsInjective: acme/a.b vs acme/a/b, acme/corp/x vs acme.corp/x, and acme/a.b/c vs acme/a/b.c.
before the fix: 6 failed, 18 passed
after the fix:  24 passed in 0.27s

Parity with the server: a throwaway Go test on #33's branch (91eb76b) printed Subject() for the same five URIs, and the output is identical to _subject():

priompt://acme/support/agent-v2_x -> priompt.acme.support.agent-v2_x
priompt://acme.corp/x/a.b -> priompt.acme%2Ecorp.x.a%2Eb
priompt://a/*/> -> priompt.a.%2A.%3E
priompt://a/café -> priompt.a.caf%C3%A9
priompt://a/b/ -> priompt.a.b.

Real run against a server built from #33's branch: subscribe to both URIs, then publish to each.

before:  priompt://acme/support/agent events: 1    priompt://acme.corp/x/a.b events: 0
after:   priompt://acme/support/agent events: 1    priompt://acme.corp/x/a.b events: 1

Compatibility

This matches the server after #33. Against a v0.7.2 server, URIs with a dot in a segment would stop getting events, because that server still publishes on the unencoded subject. Dot-free URIs work with both. Release this in step with priompt/priompt#33.

Fixes #10

🤖 Generated with Claude Code

The server now maps each URI segment to one subject token and
percent-encodes every byte outside [A-Za-z0-9_-] with uppercase hex
(priompt/priompt#33), so priompt://acme.corp/x/a.b publishes on
priompt.acme%2Ecorp.x.a%2Eb. _subject() only replaced "/" with ".", so
subscribe() listened on the wrong subject for any URI with a dot in a
segment. Dot-free URIs keep the same subject.

Fixes #10

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sujal-maheshwari2004
sujal-maheshwari2004 merged commit 873c53e into main Oct 18, 2026
1 check passed
@sujal-maheshwari2004
sujal-maheshwari2004 deleted the fix/10-subject-encoding branch October 18, 2026 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Match the server's subject encoding for segments with dots

1 participant