Skip to content

A "Replace" property function can call "Regex.Replace(...)" even if the receiver type is not "Regex" #12923

@DustinCampbell

Description

@DustinCampbell

Issue Description

I'm creating an issue to reference in a PR I'm about to submit for a bug I spotted.

Essentially, Regex.Replace(string input, string pattern, string replacement) will be called if the receiver type is something other than Regex under certain conditions:

  1. The receiver type must be included in AvailableStaticMethods (or the MSBUILDENABLEALLPROPERTYFUNCTIONS must be set).
  2. The receiver type must not already be handled by WellKnownFunctions.

Steps to Reproduce

Employ a property expression that matches the criteria specified above. For example, this expression will trigger the problem:

$([System.TimeSpan]::Replace('abc_123_ghi', '\\d+', 'def'))

Expected Behavior

Regex.Replace(string input, string pattern, string replacement) shouldn't be called unless the property function is for

Actual Behavior

An InvalidProjectFileException should be thrown, or the correct Replace method on the given receiver type, if one exists.

Analysis

This is a regression that was introduced with commit 59a6e31 (merged from PR #10409). It looks like it was just a copy paste fail when cleaning up the PR changes.

Versions & Configurations

No response

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions