Skip to content

Commit 86905c1

Browse files
Decoded URI component on ref value (#1033)
* decodedURIComponent on ref value Signed-off-by: msivasubramaniaan <[email protected]> * fixed test case Signed-off-by: msivasubramaniaan <[email protected]> --------- Signed-off-by: msivasubramaniaan <[email protected]>
1 parent f6bccf5 commit 86905c1

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/languageservice/services/yamlSchemaService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ export class YAMLSchemaService extends JSONSchemaService {
279279
const handleRef = (next: JSONSchema): void => {
280280
const seenRefs = new Set();
281281
while (next.$ref) {
282-
const ref = next.$ref;
282+
const ref = decodeURIComponent(next.$ref);
283283
const segments = ref.split('#', 2);
284284
//return back removed $ref. We lost info about referenced type without it.
285285
next._$ref = next.$ref;

test/schemaValidation.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,4 +2027,31 @@ obj:
20272027
['Missing property "form".'] // not inclide provider error
20282028
);
20292029
});
2030+
2031+
it('URL-encoded characters in $ref', async () => {
2032+
// note that 'missing form property' is necessary to trigger the bug (there has to be some problem in both subSchemas)
2033+
// order of the object in `anyOf` is also important
2034+
const schema: JSONSchema = {
2035+
type: 'object',
2036+
properties: {
2037+
myProperty: {
2038+
$ref: '#/definitions/Interface%3Ctype%3E',
2039+
},
2040+
},
2041+
definitions: {
2042+
'Interface<type>': {
2043+
type: 'object',
2044+
properties: {
2045+
foo: {
2046+
type: 'string',
2047+
},
2048+
},
2049+
},
2050+
},
2051+
};
2052+
schemaProvider.addSchema(SCHEMA_ID, schema);
2053+
const content = `myProperty:\n foo: bar`;
2054+
const result = await parseSetup(content);
2055+
assert.equal(result.length, 0);
2056+
});
20302057
});

0 commit comments

Comments
 (0)