Skip to content

Reject misleading UTF-16 string length exports - #8470

Closed
Marve10s wants to merge 1 commit into
Effect-TS:mainfrom
Marve10s:fix/schema-utf16-json-export
Closed

Marve10s wants to merge 1 commit into
Effect-TS:mainfrom
Marve10s:fix/schema-utf16-json-export

Conversation

@Marve10s

Copy link
Copy Markdown
Contributor

Exporting Schema.String.check(Schema.isMaxLength(1)) currently produces { type: "string", maxLength: 1 }. Effect rejects "😀" because it has two UTF-16 code units, while that JSON Schema accepts it as one Unicode code point. isMinLength(2) has the reverse problem: the exported schema rejects a value that Effect accepts.

This addresses the string-length export part of #8358 and the mismatch reported in #6336. It builds on #8459, which fixes JSON Schema imports. Importing JSON Schema and exporting existing UTF-16 checks are separate paths.

The chosen approach preserves the runtime meaning of isMinLength, isMaxLength, and isBetweenLength. Their JSON Schema callbacks now reject unsupported string bounds with an error directing callers to the corresponding code-point check or an explicit toJsonSchema check annotation. Array mappings, code-point checks, and the supported empty/non-empty string cases continue to export.

This is an intentional compatibility change for JSON Schema generation and a proposal for maintainer review. Existing callers that export nontrivial UTF-16 string bounds, including Schema.Char, will now receive an error. Switching to code-point checks also changes runtime validation; applications that need UTF-16 semantics must retain those checks and provide a deliberate export mapping. The PR implements the explicit-refusal direction described in #8358 without adding a general strict-export mode.

The regression cases cover both export entry points, nested definitions, unchanged emoji validation, and a custom mapping checked against BMP characters, astral characters, combining sequences, lone surrogates, and line breaks. Existing annotation/reference examples now use code-point checks where their expected output is a JSON Schema length bound.

Other check mappings in #8358 remain outside this PR.

@changeset-bot

changeset-bot Bot commented Sep 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 25fbf42

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 31 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/ai-typesafe Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-deno Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/docgen Patch
@effect/doctest Patch
@effect/openapi-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@effect-janitor effect-janitor Bot added the 4.0 label Sep 23, 2026
@gcanti

gcanti commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Closing in favor of #8482

@gcanti gcanti closed this Sep 24, 2026

This branch is waiting to be deployed

1 waiting deployment
fork — 25fbf42a Waiting Sep 23, 2026 by Marve10s via approval-gate #27159
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants