// Bug: splits the path with a permissive regex (invalid paths accepted) and walks with plain indexing, so inherited props and string "length" leak through.export class PathError extends Error { constructor( public readonly kind: "invalid_path", public readonly path: string, ) { super(`${kind}: ${path}`); }}export function getPath(obj: unknown, path: string): unknown { if (!path) throw new PathError("invalid_path", path); const parts = path.split(/[.[\]]+/).filter(Boolean); let cur: any = obj; for (const part of parts) { if (cur == null) return undefined; cur = cur[part]; } return cur ?? undefined;}