From 2016ad74570dc8aef472bada49348a75460c09d3 Mon Sep 17 00:00:00 2001 From: Libby Date: Sat, 7 Nov 2026 19:36:32 +0000 Subject: [PATCH] cultnet-ts: write_not_authorized blank-reason check is C# IsNullOrWhiteSpace Review: trim() differs from string.IsNullOrWhiteSpace on U+0085 and U+FEFF; use the package's isNullOrWhiteSpaceCSharp and pin both in the test. Co-Authored-By: Claude Sonnet 5.5 --- packages/cultnet-ts/src/contracts.ts | 3 ++- packages/cultnet-ts/test/cultnet-error.test.ts | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/cultnet-ts/src/contracts.ts b/packages/cultnet-ts/src/contracts.ts index 972a1023..bc6a7b72 100644 --- a/packages/cultnet-ts/src/contracts.ts +++ b/packages/cultnet-ts/src/contracts.ts @@ -1,3 +1,4 @@ +import { isNullOrWhiteSpaceCSharp } from "./cultmesh-authority"; import type { DocumentPayload } from "@gamecult/cultcache-ts/document"; import Ajv2020, { type ValidateFunction } from "ajv/dist/2020.js"; @@ -211,7 +212,7 @@ export function cultNetTextError(error: string): CultNetErrorMessage { export function cultNetWriteNotAuthorizedError(recordKey: string, reason?: string | null): CultNetErrorMessage { return { schemaVersion: "cultnet.error.v0", - error: reason && reason.trim() ? `write_not_authorized: ${reason}` : "write_not_authorized", + error: typeof reason === "string" && !isNullOrWhiteSpaceCSharp(reason) ? `write_not_authorized: ${reason}` : "write_not_authorized", routingHint: null, code: "write_not_authorized", details: { field: "recordKey", value: recordKey, asOf: null, current: null }, diff --git a/packages/cultnet-ts/test/cultnet-error.test.ts b/packages/cultnet-ts/test/cultnet-error.test.ts index 41b1698e..e234f105 100644 --- a/packages/cultnet-ts/test/cultnet-error.test.ts +++ b/packages/cultnet-ts/test/cultnet-error.test.ts @@ -93,4 +93,7 @@ test("a write_not_authorized refusal with no reason, or a blank one, says only t assert.equal(cultNetWriteNotAuthorizedError("k").error, "write_not_authorized"); assert.equal(cultNetWriteNotAuthorizedError("k", " ").error, "write_not_authorized"); assert.equal(cultNetWriteNotAuthorizedError("k", null).error, "write_not_authorized"); + // C# string.IsNullOrWhiteSpace counts U+0085 as white space and not U+FEFF; JS trim() disagrees on both. + assert.equal(cultNetWriteNotAuthorizedError("k", "\u0085").error, "write_not_authorized"); + assert.equal(cultNetWriteNotAuthorizedError("k", "\ufeff").error, "write_not_authorized: \ufeff"); });