Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add special case for MIParser to parse 'objects' with values but no keys #313

Merged
merged 4 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/MIParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export class MIParser {
protected handleString() {
let str = '';
for (let c = this.next(); c; c = this.next()) {
if (c === '=' || c === ',') {
if (c === '=' || c === ',' || c === '}') {
this.back();
return str;
} else {
Expand All @@ -177,13 +177,21 @@ export class MIParser {
const result: any = {};
if (c === '{') {
c = this.next();
let key = 0;
while (c !== '}') {
if (c !== ',') {
this.back();
}
const name = this.handleString();
if (this.next() === '=') {
result[name] = this.handleValue();
} else {
/**
* e.g. script={"p 123","p 321","p 789"} will be parsed into object
* { script: { '0': 'p 123', '1': 'p 321', '2': 'p 789' } }
*/
result[key++] = name.slice(1, name.length - 1); // Remove the surrounding quotation marks.
this.back();
}
c = this.next();
}
Expand Down
19 changes: 19 additions & 0 deletions src/integration-tests/miparser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,23 @@ describe('MI Parser Test Suite', function () {
'stdout'
);
});

it('structure that starts with a curly bracket and contains values but not keys', async function () {
parser.parseLine(
'+message,bkpt={number="1",type="breakpoint",thread-groups=["i1"],script={"p 123","p 321","p 789"}}'
);
sinon.assert.calledOnceWithExactly(
gdbBackendMock.emit as sinon.SinonStub,
'statusAsync',
'message',
{
bkpt: {
number: '1',
type: 'breakpoint',
'thread-groups': ['i1'],
script: { '0': 'p 123', '1': 'p 321', '2': 'p 789' },
},
}
);
});
});