Skip to content

Commit f9a9684

Browse files
committed
Add regression test for equivalent bigint map keys
1 parent 37a7b17 commit f9a9684

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

src/languageservice/parser/ast-converter.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,19 @@ function convertScalar(node: Scalar, parent: ASTNode): ASTNode {
145145
result.isInteger = Number.isInteger(result.value);
146146
return result;
147147
}
148+
case 'bigint': {
149+
const numberValue = Number(node.value);
150+
if (Number.isSafeInteger(numberValue)) {
151+
const result = new NumberASTNodeImpl(parent, node, ...toOffsetLength(node.range));
152+
result.value = numberValue;
153+
result.isInteger = true;
154+
return result;
155+
}
156+
157+
const result = new StringASTNodeImpl(parent, node, ...toOffsetLength(node.range));
158+
result.value = node.value.toString();
159+
return result;
160+
}
148161
default: {
149162
// fail safe converting, we need to return some node anyway
150163
const result = new StringASTNodeImpl(parent, node, ...toOffsetLength(node.range));

src/languageservice/parser/yamlParser07.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export function parse(text: string, parserOptions: ParserOptions = defaultOption
3232
customTags: getCustomTags(parserOptions.customTags),
3333
version: parserOptions.yamlVersion ?? defaultOptions.yamlVersion,
3434
keepSourceTokens: true,
35+
intAsBigInt: true,
3536
};
3637
const composer = new Composer(options);
3738
const lineCounter = new LineCounter();

test/yamlValidation.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,4 +385,19 @@ alpha: 1`;
385385
expect(result).to.be.empty;
386386
});
387387
});
388+
389+
describe('Map key duplication Tests', () => {
390+
it('should not report big integer key duplication error', async () => {
391+
const yaml = '123456789012345671: 1\n123456789012345672: 2';
392+
const result = await parseSetup(yaml);
393+
expect(result).to.be.empty;
394+
});
395+
396+
it('should report duplication when bigint keys match across formats', async () => {
397+
const yaml = '123456789012345671: 1\n0x1b69b4ba630f347: 2';
398+
const result = await parseSetup(yaml);
399+
expect(result).not.to.be.empty;
400+
expect(result[0].message).to.include('Map keys must be unique');
401+
});
402+
});
388403
});

0 commit comments

Comments
 (0)