Skip to content

Commit 2f34acf

Browse files
authored
Handle case when schema not JS object (#656)
* Handle case when schema not JS object Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com> * Change test name Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>
1 parent 2a6da17 commit 2f34acf

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/languageservice/parser/jsonParser07.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,11 @@ function validate(
610610
return;
611611
}
612612

613+
// schema should be an Object
614+
if (typeof schema !== 'object') {
615+
return;
616+
}
617+
613618
if (!schema.url) {
614619
schema.url = originalSchema.url;
615620
}

src/languageservice/services/yamlSchemaService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ export class YAMLSchemaService extends JSONSchemaService {
379379
const highestPrioSchemas = this.highestPrioritySchemas(schemas);
380380
const schemaHandle = super.createCombinedSchema(resource, highestPrioSchemas);
381381
return schemaHandle.getResolvedSchema().then((schema) => {
382-
if (schema.schema && typeof schema.schema !== 'string') {
382+
if (schema.schema && typeof schema.schema === 'object') {
383383
schema.schema.url = schemaHandle.url;
384384
}
385385

test/schemaValidation.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,15 @@ obj:
15601560
});
15611561

15621562
describe('Bug fixes', () => {
1563+
it('should handle not valid schema object', async () => {
1564+
const schema = 'Foo';
1565+
languageService.addSchema(SCHEMA_ID, schema as JSONSchema);
1566+
const content = `foo: bar`;
1567+
const result = await parseSetup(content);
1568+
expect(result).to.be.empty;
1569+
expect(telemetry.messages).to.be.empty;
1570+
});
1571+
15631572
it('should handle bad schema refs', async () => {
15641573
const schema = {
15651574
type: 'object',

0 commit comments

Comments
 (0)