Skip to content

Commit d4a4c28

Browse files
committed
fix: prevent unique symbols with different lib versions
1 parent ab42b6e commit d4a4c28

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/structs/sensitive.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import type { AnyStruct } from '../utils.js';
55

66
export const SENSITIVE_REDACTED = '***';
77

8-
// Unique brand set on every struct created by `sensitive()`. Because the
9-
// `Struct` constructor copies Symbol-keyed properties from its `props` spread,
10-
// any wrapper built with `new Struct({ ...sensitiveStruct, ... })` inherits
11-
// the brand automatically — no manual tracking required.
12-
const SENSITIVE_BRAND: unique symbol = Symbol('sensitive');
8+
// Global-registry Symbol so the brand is shared across multiple instances of
9+
// this library loaded in the same runtime (e.g. npm dedup failure). Compare
10+
// with `ExactOptionalBrand`, which uses a plain string for the same reason.
11+
// Using Symbol.for() (not Symbol()) means isSensitiveStruct() works even when
12+
// `sensitive()` and `object()` come from different copies of this package.
13+
const SENSITIVE_BRAND = Symbol.for('superstruct.sensitive');
1314

1415
/**
1516
* Check whether a struct was created by `sensitive()`, or wraps one.

0 commit comments

Comments
 (0)