Skip to content

Commit

Permalink
Fix Kattis parser when sample has no input
Browse files Browse the repository at this point in the history
  • Loading branch information
jmerle committed Dec 31, 2024
1 parent 4cbb61d commit 08d9b9e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased
- Added support for the codeforces.net mirror of Codeforces and fixed support for the codeforc.es mirror on problem pages
- Fixed the Lanqiao problem parser
- Fixed the Kattis parser for samples containing only output

## [2.57.1](https://github.com/jmerle/competitive-companion/releases/tag/2.57.1) (2024-11-15)
- Added the `X-Competitive-Companion` header to HTTP requests sent by Competitive Companion to indicate to the receiving end that the request is coming from Competitive Companion (thanks [@touhidurrr](https://github.com/touhidurrr))
Expand Down
2 changes: 1 addition & 1 deletion src/models/Test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export class Test {
.trimEnd();
}

return data.endsWith('\n') ? data : data + '\n';
return data.endsWith('\n') || data.length === 0 ? data : data + '\n';
}
}
11 changes: 7 additions & 4 deletions src/parsers/problem/KattisProblemParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ export class KattisProblemParser extends Parser {
task.setMemoryLimit(parseInt(/(\d+) MB/.exec(limitsStr)[1], 10));

elem.querySelectorAll('.sample').forEach(table => {
const blocks = table.querySelectorAll('pre');
if (blocks.length > 0) {
task.addTest(blocks[0].textContent, blocks.length > 1 ? blocks[1].textContent : '', false);
}
const inputBlock = table.querySelector('tbody > tr:last-child > td:first-child > pre');
const outputBlock = table.querySelector('tbody > tr:last-child > td:last-child > pre');

const input = inputBlock !== null ? inputBlock.textContent : '';
const output = outputBlock !== null ? outputBlock.textContent : '';

task.addTest(input, output, false);
});

return task.build();
Expand Down

0 comments on commit 08d9b9e

Please sign in to comment.