From 05a9e8952448f30f89f81439739d29bd446c907c Mon Sep 17 00:00:00 2001 From: Plai Date: Thu, 9 Nov 2023 17:31:50 +0700 Subject: [PATCH] Fix dotnet build parser to recognize path with space (#161) Co-authored-by: pdujtipiya --- src/Parser/DotnetBuildParser.spec.ts | 8 ++++++++ src/Parser/DotnetBuildParser.ts | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Parser/DotnetBuildParser.spec.ts b/src/Parser/DotnetBuildParser.spec.ts index 867e3e5..63137f0 100644 --- a/src/Parser/DotnetBuildParser.spec.ts +++ b/src/Parser/DotnetBuildParser.spec.ts @@ -7,6 +7,7 @@ describe('DotnetBuildParser tests', () => { const cwdUnix = '/dir'; const logWithSource = `1:7>C:\\source\\Broken.cs(6,8): warning AG0030: Prevent use of dynamic [C:\\source\\Broken.csproj]`; + const logWithSourceWithSpace = `1:7>C:\\source\\some dir\\Broken.cs(6,8): warning AG0030: Prevent use of dynamic [C:\\source\\some dir\\Broken.csproj]`; const logWithNoSource = `1:7>CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [C:\\source\\Broken.csproj]`; const logWithUnrelatedSource = `9:8>/usr/share/dotnet/sdk/3.1.402/Microsoft.Common.CurrentVersion.targets(2084,5): warning MSB3277: some message [/dir/Tests/project.csproj]`; const contentWithNoPathAtTheEnd = `13:11>/dir/File.csproj : warning NU1701: This package may not be fully compatible with your project.`; @@ -78,4 +79,11 @@ describe('DotnetBuildParser tests', () => { it('should ignore multiline-part messages', () => { expect(() => new DotnetBuildParser(cwdUnix).parse(multilinePart)).not.toThrowError(); }); + + it('should handle path with space', () => { + const items = new DotnetBuildParser(cwdWin).parse(logWithSourceWithSpace); + const result = items[0]; + + expect(result.source).toBe('some dir/Broken.cs'); + }); }); diff --git a/src/Parser/DotnetBuildParser.ts b/src/Parser/DotnetBuildParser.ts index 14de9ba..660d64a 100644 --- a/src/Parser/DotnetBuildParser.ts +++ b/src/Parser/DotnetBuildParser.ts @@ -19,7 +19,7 @@ export class DotnetBuildParser extends Parser { private toLintItem(log: string): LintItem { const structureMatch = log.match( - /(?:[\d:>]+)?([^ ()]+)(?:\((\d+),(\d+)\))? *: *(\w+) *(\w+) *: *([^\[]+)(?:\[(.+)])?$/, + /(?:[\d:>]+)?([^>()]+)(?:\((\d+),(\d+)\))? *: *(\w+) *(\w+) *: *([^\[]+)(?:\[(.+)])?$/, ); if (!structureMatch) { const message = "DotnetBuildParser Error: log structure doesn't match";