microsoft / vscode-makefile-tools

MAKE integration in Visual Studio Code
Other
194 stars 58 forks source link

Update regex in parser.ts to remedy issue #441 #442

Closed nick-hebi closed 1 year ago

nick-hebi commented 1 year ago

https://github.com/microsoft/vscode-makefile-tools/issues/441

gcampbell-msft commented 1 year ago

@nick-hebi This is a nit, but could you leave a comment, similar to the comment from your issue you posted, that explains the need for the change? It could be useful for context for any future development.

nick-hebi commented 1 year ago

Copied from the issue for visibility:

This is a bug that is related to the regex on Line 55 of parser.ts. The extension fails to recognize build targets in the Makefile that are a single character long (such as "A:").

I believe that this regex should be changed from "^(?!\\n?[#\\.])(?<!^\\n?# Not a target:\\s*)\\s*(\\S+[^:]):\\s+" to "^(?!\\n?[#\\.])(?<!^\\n?# Not a target:\\s*)\\s*(\\S*[^:]):\\s+".

This regex is checking for a group of characters that ends in a single ':' character. The usage of (\\S+[^:]) fails on single character build target cases such as "A:" because the + consumes the first character and causes the [^:] condition to fail. Changing the + to a * remedies this issue while preserving the intended behavior of this line.

gcampbell-msft commented 1 year ago

I just did some simple testing and everything seemed to behave as normal, as well as fixing the bug. Approving!