Skip to content

Commit

Permalink
fix: fix MessageLocation.end being corrupted (wrong type) for YAML pa…
Browse files Browse the repository at this point in the history
…rse errors

We returned a plain object that stood in for a SourcePosition, but
MessageLocation does instanceof SourcePosition checks. Also added a
safeguard to the constructor now.
  • Loading branch information
Yogu committed Jan 14, 2025
1 parent f2dab64 commit 06a55d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/model/validation/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ export class MessageLocation {
value: new ProjectSource(this.sourceName, ''),
});
}

if (typeof _start !== 'number' && !(_start instanceof SourcePosition)) {
throw new Error(`start must be either a number or a SourcePosition`);
}
if (typeof _end !== 'number' && !(_end instanceof SourcePosition)) {
throw new Error(`end must be either a number or a SourcePosition`);
}
}

static from(location: LocationLike | undefined): MessageLocation | undefined {
Expand Down
2 changes: 1 addition & 1 deletion src/schema/schema-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,5 +256,5 @@ export function getLineEndPosition(targetLine: number, source: ProjectSource): S
}
}

return { line: targetLine, offset: curIndex - 1, column: column };
return new SourcePosition(curIndex - 1, targetLine, column);
}

0 comments on commit 06a55d4

Please sign in to comment.