Skip to content

Fix detection of embedded c# code#82033

Merged
CyrusNajmabadi merged 1 commit into
dotnet:mainfrom
CyrusNajmabadi:csharpDetection
Jan 16, 2026
Merged

Fix detection of embedded c# code#82033
CyrusNajmabadi merged 1 commit into
dotnet:mainfrom
CyrusNajmabadi:csharpDetection

Conversation

@CyrusNajmabadi

@CyrusNajmabadi CyrusNajmabadi commented Jan 15, 2026

Copy link
Copy Markdown
Contributor

// lang=c# wasn't working as the regex we had didn't like a # at the end.

Looks like this:

image

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner January 15, 2026 23:03
{
var namePortion = string.Join("|", identifiers.Select(n => $"({Regex.Escape(n)})"));
_regex = new Regex($@"^((//)|(')|(/\*))\s*lang(uage)?\s*=\s*(?<identifier>{namePortion})\b((\s*,\s*)(?<option>[a-zA-Z]+))*",
_regex = new Regex($@"^((//)|(')|(/\*))\s*lang(uage)?\s*=\s*(?<identifier>{namePortion})(?!\w)((\s*,\s*)(?<option>[a-z]+))*",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from Stephen. ?!\w is a better choice saying no match if we are immedaitely followed by a letter. (we don't want Routebad to match Route. And we don't need A-Z because we're already passing IgnoreCase below.

@CyrusNajmabadi

Copy link
Copy Markdown
Contributor Author

@JoeRobich ptal. :)

@CyrusNajmabadi CyrusNajmabadi merged commit 18733e8 into dotnet:main Jan 16, 2026
25 of 26 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the csharpDetection branch January 16, 2026 00:23
@dotnet-policy-service dotnet-policy-service Bot added this to the Next milestone Jan 16, 2026
@davidwengier davidwengier modified the milestones: Next, 18.4 Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants