Skip to content

Commit 46df435

Browse files
(GH-11401) Clarify smart quotes behavior/guidance (#11404)
Prior to this change, the `about_Quoting_Rules` topic document didn't indicate that PowerShell treats smart/typographic quotation marks as normal/programmer quotation marks, making them subject to the same escaping and quoting behaviors. This change: - Adds a note about smart quotation marks and guidance to avoid using them to enclose strings. - Adds an example of escaping smart quotation marks. - Fixes AB#309820 - Resolves #11401
1 parent f95e142 commit 46df435

File tree

4 files changed

+137
-37
lines changed

4 files changed

+137
-37
lines changed

reference/5.1/Microsoft.PowerShell.Core/About/about_Quoting_Rules.md

+35-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes rules for using single and double quotation marks in PowerShell.
33
Locale: en-US
4-
ms.date: 09/04/2024
4+
ms.date: 09/09/2024
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-5.1&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Quoting_Rules
@@ -34,6 +34,16 @@ command that are run on the remote computer. In a remote session, quotation
3434
marks also determine whether the variables in a command are interpreted first
3535
on the local computer or on the remote computer.
3636

37+
> PowerShell treats smart quotation marks, also called typographic or curly
38+
> quotes, as normal quotation marks for strings. Don't use smart quotation
39+
> marks to enclose strings. When writing strings that contain smart quotation
40+
> marks, follow the guidance in the
41+
> [Including quote characters in a string](#including-quote-characters-in-a-string)
42+
> section of this document.
43+
>
44+
> For more information about smart quotation marks, see the _Smart Quotes_
45+
> section in the Wikipedia article [Quotation marks in English][02].
46+
3747
## Double-quoted strings
3848

3949
A string enclosed in double quotation marks is an _expandable_ string. Variable
@@ -75,7 +85,7 @@ enclosed in a subexpression. For example:
7585
```
7686

7787
```Output
78-
PS version: 5.1.19041.1151
88+
PS version: 7.2.0
7989
```
8090

8191
To separate a variable name from subsequent characters in the string, enclose
@@ -204,6 +214,20 @@ Use a quotation mark (") to begin a string.
204214
Use a quotation mark (`") to begin a string.
205215
```
206216

217+
Because PowerShell interprets smart quotation marks, like ``, `'`, ``, and
218+
``, as normal quotation marks, smart quotation marks also need to be escaped.
219+
For example:
220+
221+
```powershell
222+
"Double ““smart quotation marks`” must be escaped in a double-quoted string."
223+
'Single ‘‘smart quotation marks’’ must be escaped in a single-quoted string.'
224+
```
225+
226+
```Output
227+
Double “smart quotation marks” must be escaped in a double-quoted string.
228+
Single ‘smart quotation marks’ must be escaped in a single-quoted string.
229+
```
230+
207231
## Here-strings
208232

209233
The quotation rules for here-strings are slightly different.
@@ -360,7 +384,7 @@ see in the console.
360384
Collections, including arrays, are converted to strings by placing a single
361385
space between the string representations of the elements. A different separator
362386
can be specified by setting preference variable `$OFS`. For more information,
363-
see the [`$OFS` preference variable][03].
387+
see the [`$OFS` preference variable][04].
364388

365389
Instances of any other type are converted to strings by calling the
366390
`ToString()` method, which may not give a meaningful representation. For
@@ -430,16 +454,17 @@ Some native commands expect arguments that contain quote characters. PowerShell
430454
interprets the quoted string before passing it to the external command. This
431455
interpretation removes the outer quote characters.
432456

433-
For more information about this behavior, see the [about_Parsing][02] article.
457+
For more information about this behavior, see the [about_Parsing][03] article.
434458

435459
## See also
436460

437-
- [about_Special_Characters][04]
438-
- [ConvertFrom-StringData][05]
461+
- [about_Special_Characters][05]
462+
- [ConvertFrom-StringData][06]
439463

440464
<!-- link references -->
441465
[01]: about_Parsing.md#argument-mode
442-
[02]: about_Parsing.md#passing-arguments-that-contain-quote-characters
443-
[03]: about_preference_variables.md#ofs
444-
[04]: about_Special_Characters.md
445-
[05]: xref:Microsoft.PowerShell.Utility.ConvertFrom-StringData
466+
[02]: https://en.wikipedia.org/wiki/Quotation_marks_in_English#Smart_quotes
467+
[03]: about_Parsing.md#passing-arguments-that-contain-quote-characters
468+
[04]: about_preference_variables.md#ofs
469+
[05]: about_Special_Characters.md
470+
[06]: xref:Microsoft.PowerShell.Utility.ConvertFrom-StringData

reference/7.2/Microsoft.PowerShell.Core/About/about_Quoting_Rules.md

+34-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes rules for using single and double quotation marks in PowerShell.
33
Locale: en-US
4-
ms.date: 09/04/2024
4+
ms.date: 09/09/2024
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7.2&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Quoting_Rules
@@ -34,6 +34,16 @@ command that are run on the remote computer. In a remote session, quotation
3434
marks also determine whether the variables in a command are interpreted first
3535
on the local computer or on the remote computer.
3636

37+
> PowerShell treats smart quotation marks, also called typographic or curly
38+
> quotes, as normal quotation marks for strings. Don't use smart quotation
39+
> marks to enclose strings. When writing strings that contain smart quotation
40+
> marks, follow the guidance in the
41+
> [Including quote characters in a string](#including-quote-characters-in-a-string)
42+
> section of this document.
43+
>
44+
> For more information about smart quotation marks, see the _Smart Quotes_
45+
> section in the Wikipedia article [Quotation marks in English][02].
46+
3747
## Double-quoted strings
3848

3949
A string enclosed in double quotation marks is an _expandable_ string. Variable
@@ -204,6 +214,20 @@ Use a quotation mark (") to begin a string.
204214
Use a quotation mark (`") to begin a string.
205215
```
206216

217+
Because PowerShell interprets smart quotation marks, like ``, `'`, ``, and
218+
``, as normal quotation marks, smart quotation marks also need to be escaped.
219+
For example:
220+
221+
```powershell
222+
"Double ““smart quotation marks`” must be escaped in a double-quoted string."
223+
'Single ‘‘smart quotation marks’’ must be escaped in a single-quoted string.'
224+
```
225+
226+
```Output
227+
Double “smart quotation marks” must be escaped in a double-quoted string.
228+
Single ‘smart quotation marks’ must be escaped in a single-quoted string.
229+
```
230+
207231
## Here-strings
208232

209233
The quotation rules for here-strings are slightly different.
@@ -360,7 +384,7 @@ see in the console.
360384
Collections, including arrays, are converted to strings by placing a single
361385
space between the string representations of the elements. A different separator
362386
can be specified by setting preference variable `$OFS`. For more information,
363-
see the [`$OFS` preference variable][03].
387+
see the [`$OFS` preference variable][04].
364388

365389
Instances of any other type are converted to strings by calling the
366390
`ToString()` method, which may not give a meaningful representation. For
@@ -430,16 +454,17 @@ Some native commands expect arguments that contain quote characters. PowerShell
430454
interprets the quoted string before passing it to the external command. This
431455
interpretation removes the outer quote characters.
432456

433-
For more information about this behavior, see the [about_Parsing][02] article.
457+
For more information about this behavior, see the [about_Parsing][03] article.
434458

435459
## See also
436460

437-
- [about_Special_Characters][04]
438-
- [ConvertFrom-StringData][05]
461+
- [about_Special_Characters][05]
462+
- [ConvertFrom-StringData][06]
439463

440464
<!-- link references -->
441465
[01]: about_Parsing.md#argument-mode
442-
[02]: about_Parsing.md#passing-arguments-that-contain-quote-characters
443-
[03]: about_preference_variables.md#ofs
444-
[04]: about_Special_Characters.md
445-
[05]: xref:Microsoft.PowerShell.Utility.ConvertFrom-StringData
466+
[02]: https://en.wikipedia.org/wiki/Quotation_marks_in_English#Smart_quotes
467+
[03]: about_Parsing.md#passing-arguments-that-contain-quote-characters
468+
[04]: about_preference_variables.md#ofs
469+
[05]: about_Special_Characters.md
470+
[06]: xref:Microsoft.PowerShell.Utility.ConvertFrom-StringData

reference/7.4/Microsoft.PowerShell.Core/About/about_Quoting_Rules.md

+34-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes rules for using single and double quotation marks in PowerShell.
33
Locale: en-US
4-
ms.date: 09/04/2024
4+
ms.date: 09/09/2024
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7.4&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Quoting_Rules
@@ -34,6 +34,16 @@ command that are run on the remote computer. In a remote session, quotation
3434
marks also determine whether the variables in a command are interpreted first
3535
on the local computer or on the remote computer.
3636

37+
> PowerShell treats smart quotation marks, also called typographic or curly
38+
> quotes, as normal quotation marks for strings. Don't use smart quotation
39+
> marks to enclose strings. When writing strings that contain smart quotation
40+
> marks, follow the guidance in the
41+
> [Including quote characters in a string](#including-quote-characters-in-a-string)
42+
> section of this document.
43+
>
44+
> For more information about smart quotation marks, see the _Smart Quotes_
45+
> section in the Wikipedia article [Quotation marks in English][02].
46+
3747
## Double-quoted strings
3848

3949
A string enclosed in double quotation marks is an _expandable_ string. Variable
@@ -204,6 +214,20 @@ Use a quotation mark (") to begin a string.
204214
Use a quotation mark (`") to begin a string.
205215
```
206216

217+
Because PowerShell interprets smart quotation marks, like ``, `'`, ``, and
218+
``, as normal quotation marks, smart quotation marks also need to be escaped.
219+
For example:
220+
221+
```powershell
222+
"Double ““smart quotation marks`” must be escaped in a double-quoted string."
223+
'Single ‘‘smart quotation marks’’ must be escaped in a single-quoted string.'
224+
```
225+
226+
```Output
227+
Double “smart quotation marks” must be escaped in a double-quoted string.
228+
Single ‘smart quotation marks’ must be escaped in a single-quoted string.
229+
```
230+
207231
## Here-strings
208232

209233
The quotation rules for here-strings are slightly different.
@@ -360,7 +384,7 @@ see in the console.
360384
Collections, including arrays, are converted to strings by placing a single
361385
space between the string representations of the elements. A different separator
362386
can be specified by setting preference variable `$OFS`. For more information,
363-
see the [`$OFS` preference variable][03].
387+
see the [`$OFS` preference variable][04].
364388

365389
Instances of any other type are converted to strings by calling the
366390
`ToString()` method, which may not give a meaningful representation. For
@@ -430,16 +454,17 @@ Some native commands expect arguments that contain quote characters. PowerShell
430454
interprets the quoted string before passing it to the external command. This
431455
interpretation removes the outer quote characters.
432456

433-
For more information about this behavior, see the [about_Parsing][02] article.
457+
For more information about this behavior, see the [about_Parsing][03] article.
434458

435459
## See also
436460

437-
- [about_Special_Characters][04]
438-
- [ConvertFrom-StringData][05]
461+
- [about_Special_Characters][05]
462+
- [ConvertFrom-StringData][06]
439463

440464
<!-- link references -->
441465
[01]: about_Parsing.md#argument-mode
442-
[02]: about_Parsing.md#passing-arguments-that-contain-quote-characters
443-
[03]: about_preference_variables.md#ofs
444-
[04]: about_Special_Characters.md
445-
[05]: xref:Microsoft.PowerShell.Utility.ConvertFrom-StringData
466+
[02]: https://en.wikipedia.org/wiki/Quotation_marks_in_English#Smart_quotes
467+
[03]: about_Parsing.md#passing-arguments-that-contain-quote-characters
468+
[04]: about_preference_variables.md#ofs
469+
[05]: about_Special_Characters.md
470+
[06]: xref:Microsoft.PowerShell.Utility.ConvertFrom-StringData

reference/7.5/Microsoft.PowerShell.Core/About/about_Quoting_Rules.md

+34-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes rules for using single and double quotation marks in PowerShell.
33
Locale: en-US
4-
ms.date: 09/04/2024
4+
ms.date: 09/09/2024
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7.5&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Quoting_Rules
@@ -34,6 +34,16 @@ command that are run on the remote computer. In a remote session, quotation
3434
marks also determine whether the variables in a command are interpreted first
3535
on the local computer or on the remote computer.
3636

37+
> PowerShell treats smart quotation marks, also called typographic or curly
38+
> quotes, as normal quotation marks for strings. Don't use smart quotation
39+
> marks to enclose strings. When writing strings that contain smart quotation
40+
> marks, follow the guidance in the
41+
> [Including quote characters in a string](#including-quote-characters-in-a-string)
42+
> section of this document.
43+
>
44+
> For more information about smart quotation marks, see the _Smart Quotes_
45+
> section in the Wikipedia article [Quotation marks in English][02].
46+
3747
## Double-quoted strings
3848

3949
A string enclosed in double quotation marks is an _expandable_ string. Variable
@@ -204,6 +214,20 @@ Use a quotation mark (") to begin a string.
204214
Use a quotation mark (`") to begin a string.
205215
```
206216

217+
Because PowerShell interprets smart quotation marks, like ``, `'`, ``, and
218+
``, as normal quotation marks, smart quotation marks also need to be escaped.
219+
For example:
220+
221+
```powershell
222+
"Double ““smart quotation marks`” must be escaped in a double-quoted string."
223+
'Single ‘‘smart quotation marks’’ must be escaped in a single-quoted string.'
224+
```
225+
226+
```Output
227+
Double “smart quotation marks” must be escaped in a double-quoted string.
228+
Single ‘smart quotation marks’ must be escaped in a single-quoted string.
229+
```
230+
207231
## Here-strings
208232

209233
The quotation rules for here-strings are slightly different.
@@ -360,7 +384,7 @@ see in the console.
360384
Collections, including arrays, are converted to strings by placing a single
361385
space between the string representations of the elements. A different separator
362386
can be specified by setting preference variable `$OFS`. For more information,
363-
see the [`$OFS` preference variable][03].
387+
see the [`$OFS` preference variable][04].
364388

365389
Instances of any other type are converted to strings by calling the
366390
`ToString()` method, which may not give a meaningful representation. For
@@ -430,16 +454,17 @@ Some native commands expect arguments that contain quote characters. PowerShell
430454
interprets the quoted string before passing it to the external command. This
431455
interpretation removes the outer quote characters.
432456

433-
For more information about this behavior, see the [about_Parsing][02] article.
457+
For more information about this behavior, see the [about_Parsing][03] article.
434458

435459
## See also
436460

437-
- [about_Special_Characters][04]
438-
- [ConvertFrom-StringData][05]
461+
- [about_Special_Characters][05]
462+
- [ConvertFrom-StringData][06]
439463

440464
<!-- link references -->
441465
[01]: about_Parsing.md#argument-mode
442-
[02]: about_Parsing.md#passing-arguments-that-contain-quote-characters
443-
[03]: about_preference_variables.md#ofs
444-
[04]: about_Special_Characters.md
445-
[05]: xref:Microsoft.PowerShell.Utility.ConvertFrom-StringData
466+
[02]: https://en.wikipedia.org/wiki/Quotation_marks_in_English#Smart_quotes
467+
[03]: about_Parsing.md#passing-arguments-that-contain-quote-characters
468+
[04]: about_preference_variables.md#ofs
469+
[05]: about_Special_Characters.md
470+
[06]: xref:Microsoft.PowerShell.Utility.ConvertFrom-StringData

0 commit comments

Comments
 (0)