Home Dashboard Directory Help
Search

Powershell errors with apostrophe in path by Naf3tS


Status: 

Active


6
0
Sign in
to vote
Type: Bug
ID: 278008
Opened: 5/21/2007 3:18:57 PM
Access Restriction: Public
0
Workaround(s)
view
4
User(s) can reproduce this bug

Description

The MyDocuments folder on my workstation is set to "C:\Stefan's Documents". My Powershell command prompt shortcut is configured to start in this folder (i.e. the "Start In" property of the shortcut).Windows PowerShell. Whenever I start a Powershell command prompt I get the following error:

<Snip>
Copyright (C) 2006 Microsoft Corporation. All rights reserved.

Incomplete string token.
At line:1 char:27
+ set-location 'C:\Stefan's D <<<< ocuments'
PS C:\Stefan's Documents>
</Snip>

This is pretty annoying. I've tracked the bug down to the following line in the Microsoft.Powershell.ConsoleHost.InitializeRunspace:

string command = StringUtil.Format("set-location '{0}'", Environment.CurrentDirectory);

The resultant command is "set-location 'C:\Stefan's Documents'". The apostrophe in the directory name has not been escaped properly. This issue gets worse if you create a profile in this directory (i.e. $profile = C:\Stefan's Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1).

<Snip>
Windows PowerShell
Copyright (C) 2006 Microsoft Corporation. All rights reserved.

Incomplete string token.
At line:1 char:27
+ set-location 'C:\Stefan's D <<<< ocuments'
Incomplete string token.
At line:1 char:17
+ . 'C:\Stefan`'s D <<<< ocuments\WindowsPowerShell\Microsoft.PowerShell_profile.ps1'
PS C:\Stefan's Documents>
</Snip>

In this case the code that runs profile includes a call to the EscapeTickCharacters function (see Microsoft.Powershell.ConsoleHost.RunProfile). This function prefixes an apostrophe (') with a backwards apostrophe (`). According to "get-help about_escape_character' (`') should escape the apostrophe. This second error message must therefore be a bug in the parser / tokenizer (probably StringTokenReader).
Details
Sign in to post a comment.
Posted by kradski on 1/20/2012 at 1:35 PM
Wow, this has been open since 2007, and *still* no fix. Microsoft expects people to adopt powershell--outright forces them to with Exchange 2007 and 2010--but heaven forbid you're stuck with a legacy MyDocs name that includes an apostrophe--you'll literally never be able to make specific-user@allHosts and specific-user@singlehost profiles without overhauling your entire organization. Insane.

Asking people to change their entire organization and file path structure is lazy, to say the least, when this is a clear bug that could and and should be fixed by microsoft--quickly--by just escaping the frickin' paths.

There might even be a security hole in there somewhere, too, if you think about it, much like a SQL injection attack.

Whatever.
Posted by opellegr on 12/21/2010 at 8:23 AM
I really wish you would fix this. It stinks that I'm not allowed to use user-scoped profiles because you forgot users can specify their own profile paths. Is there any timeframe for a fix? It's been 3 years since this was reported and a year since PSH 2.0.
Posted by Microsoft Connect on 9/25/2009 at 6:18 PM
Your bug has not been fixed in PowerShell 2.0. However we have kept the bug active for next version
Sign in to post a workaround.