fix(schema): reject noncanonical array refs

This commit is contained in:
Peter Steinberger
2026-05-29 04:25:04 -04:00
parent b78ebacb18
commit d4a17477b0
2 changed files with 10 additions and 2 deletions

View File

@@ -313,6 +313,13 @@ describe("schema validator", () => {
$ref: "#/$defs/Missing",
},
],
[
"schema-validator.test.invalid-array-ref-leading-zero",
{
anyOf: [{ type: "number" }, { type: "string" }],
$ref: "#/anyOf/01",
},
],
[
"schema-validator.test.invalid-dynamic-ref-type",
{

View File

@@ -1,5 +1,6 @@
import { Compile } from "typebox/compile";
import type { JsonSchemaObject } from "./json-schema.types.js";
import { parseConfigPathArrayIndex } from "./path-array-index.js";
type JsonSchemaValue = JsonSchemaObject | boolean;
type LocalRefResolution =
@@ -304,8 +305,8 @@ function resolveLocalRef(
let currentResourceBaseId = resourceBaseId;
for (const segment of ref.slice(2).split("/").map(decodePointerSegment)) {
if (Array.isArray(current)) {
const index = Number(segment);
if (!Number.isInteger(index) || index < 0) {
const index = parseConfigPathArrayIndex(segment);
if (index === undefined) {
return { found: false };
}
current = current[index];