Skip to content

Interpolated string literals without interpolation holes do not treat % characters correctly #14434

Closed
@abonie

Description

@abonie

Because % character can have a special meaning within interpolated strings (as format specifier for interpolation expressions), it needs to be escaped by doubling to be treated as literal % character. However, if an interpolated string literal has no interpolation expressions, it will not drop the extra % chars from content

Repro steps

Create an interpolated string literal without any interpolations (expressions within curly braces) and containing a substring of %%.

Expected behavior

Regardless of whether the literal contained any interpolation expressions, it treats %% as %

> //Interpolated string literal with no interpolation holes
- $"%%";;
val it: string = "%"

> //And for comparison an interpolated string literal *with* interpolation holes
- $"{42=41+1} ... %%";;
val it: string = "True ... %"

Actual behavior

> //Interpolated string literal with no interpolation holes
- $"%%";;
val it: string = "%%"

> //And for comparison an interpolated string literal *with* interpolation holes
- $"{42=41+1} ... %%";;
val it: string = "True ... %"

Known workarounds

Don't use interpolated string literals that have no interpolation holes.

Metadata

Metadata

Assignees

Labels

BugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions