Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
abonie opened this issue Dec 5, 2022 · 2 comments · Fixed by #14440
Closed
Assignees
Labels
Bug Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code.
Milestone

Comments

@abonie
Copy link
Member

abonie commented Dec 5, 2022

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.

@dsyme
Copy link
Contributor

dsyme commented Dec 5, 2022

I think we should consider this a bug fix. Perhaps protected by a version flag in case people ned to revert to the original behaviour.

@dsyme
Copy link
Contributor

dsyme commented Dec 5, 2022

(The alternative is to give an error or warning on such strings - perhaps a warning for one version, then an error, then actually make the fix. But either way, it's not intended behaviour and is a bug)

@0101 0101 added Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code. and removed Needs-Triage Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. labels Dec 5, 2022
@abonie abonie self-assigned this Dec 6, 2022
Repository owner moved this from Not Planned to Done in F# Compiler and Tooling Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants