#1 14 Nov 2012 20:35

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 867
Website

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).

Example:

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.

Offline

#2 16 Nov 2012 10:39

jumper
Member
From: tunisia, Mornaguia
Registered: 17 Apr 2009
Posts: 55
Website

Re: The dangers of Copy and Paste + TAB characters

hi

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

Offline

Board footer

Powered by FluxBB