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"); });