#1 14 Nov 2012 20:35

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 888

The dangers of Copy and Paste + TAB characters

Because PowerShell supports Tab Completion you need to be careful about copying and pasting TAB characters (which most often sneak in before comments).


Function demo() { 
} 	# comment

^ That line is }<space><tab> #
when copied/pasted onto the powershell command line:

PS C:\batch> Function demo() { 
>> } .\aaardvaark.cmd# comment 
The term '.\aaardvaark.cmd#' is not recognized as the name of a cmdlet, function, script file...

What is happening is that the space-tab gets expanded to match the first file in the current directory, in this case aaardvaark.cmd. If the sequence had been <space><tab><space> and the first file had been a PowerShell script or an executable then it would actually be run.

If your white space cosists of nothing but <space> characters (or nothing but <tab> characters) then this will never occur.


#2 16 Nov 2012 10:39

From: tunisia, Mornaguia
Registered: 17 Apr 2009
Posts: 55

Re: The dangers of Copy and Paste + TAB characters


thanks for sharing Simon,

This behavior can be solved by editing and changing the function tabexpansion in V2 and with the new tokenizer AST in V3 i think  this "problem" is easy to resolve.

sorry for my english


Board footer

Powered by FluxBB