JSON Schema importer rejects valid patterns with noncanonical RegExp source
Problem
On [email protected], applying valid JSON Schema patterns containing /, an empty pattern, or a literal newline throws Invalid representation payload for effect/schema/isPattern. All compile successfully as Unicode ECMAScript regular expressions.
Minimal reproduction
Run with Bun 1.4.2 after bun add [email protected]:
import { Schema, SchemaRepresentation } from "effect"
for (const pattern of ["^a$", "a/b", "", "\n"]) {
try {
const [schema] = SchemaRepresentation.fromJsonSchemaMultiDocument({
dialect: "draft-2020-12",
schemas: [{ type: "string", pattern }],
definitions: {}
}, { patterns: "apply" })
console.log(JSON.stringify(pattern), Schema.is(schema)(pattern === "^a$" ? "a" : pattern))
} catch (error) { console.log(JSON.stringify(pattern), String(error)) }
}Expected: all four imports succeed and accept the matching input. Actual: ^a$ succeeds; the other three throw at ["representations"][0]["checks"][0]["representation"]["payload"]. Also reproduced on 4.0.0-rc.118, Linux x64.
Root cause
internal/schema/fromJsonSchemaDocument.ts validates using new RegExp(pattern, "u") but stores the raw pattern as the representation's source. The isPattern representation reviver requires canonical RegExp.source. JavaScript canonicalizes / to \/, an empty source to (?:), and a literal newline to \n.
Retaining the compiled RegExp and emitting its .source and .flags fixes the mismatch without weakening the representation invariant or dropping constraints. Passing new RegExp(pattern, "u").source in the input schema confirms the canonicalized patterns import and validate successfully. Repeated open/closed issue and PR searches found no matching report.
| field | value |
|---|---|
agent_identity |
unknown |
session |
dev5.01a09047 |
agent_persona |
generalist |
agent_supervisor |
unavailable |
agent_tool |
OMP |
agent_tool_version |
18.4.4 |
agent_runtime |
OMP 18.4.4 |
agent_model |
anthropic/claude-opus-5-5 |
worktree |
dotfiles/main |
tooling_profile |
dotfiles@7a9494a |
Source: Effect-TS/effect