Skip to content

Commit

Permalink
fix: less restrictive map file name extraction regex (#87)
Browse files Browse the repository at this point in the history
* test: added failing test case for empty output.map.file

* fix: extract map file name without \ or /

* improvement: map file regex negative lookahead position update
  • Loading branch information
PBug90 committed May 18, 2021
1 parent 350094c commit 5731637
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const gameVersion = (version: number): string => {
return `1.${version}`;
};

const mapFilenameRegex = /(\([1-9]+\))?[a-zA-Z_0-9\w]+\.(w3x|w3m)/;
const mapFilenameRegex = /[^\\/]+(\([1-9]+\))?\.(w3x|w3m)/;
const mapFilename = (mapPath: string): string => {
const match = mapFilenameRegex.exec(mapPath);
if (match) {
Expand Down
9 changes: 9 additions & 0 deletions test/replays/131/replays.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,12 @@ it("parses a standard 1.30.4 1on1 tome of retraining", async () => {
],
});
});

test("#86 extracts correct map name", async () => {
const test = await Parser.parse(
path.resolve(__dirname, "roc-losttemple-mapname.w3g")
);
expect(test.version).toBe("1.31");
expect(test.buildNumber).toBe(6072);
expect(test.map.file).toBe("(4)LostTemple [Unforged 0.5 RoC].w3x");
});
Binary file added test/replays/131/roc-losttemple-mapname.w3g
Binary file not shown.

0 comments on commit 5731637

Please sign in to comment.