none
PowerShell formatting bug RRS feed

  • Question

  • This has been posted before many time butit never gets fixed. PowerSHell does not highlight correctly after quotes on certain lines.  The coorizing losses track of what it is doing and includes a large amount of code within a colorized quote section.

    Here is an example that is very easy to see:

    $folderA="y:\sourcefolder\" # note trailing \
    $folderB="x:\somefolder\*"  # note filemask
    $folderC="z:\targetfolder"
    # try and move all files that match folderB
    dir $folderB | %{move "$folderA$($_.Name)" $folderC -force -whatif}

    Notice that the first quote starts colorizing in green and it doesn't stop for three lines even though there is a closing quote on the same line and there are quotes on the next two lines.

    Also note that the sense of what is colorized is inverted.  Everything  in quotes is not colorized and everything outside of quotes is colored green. 

    This is very confusing.

    Is that any reason why we cannot use the code editor and colorizer from the repository?  From what I can see that one works much better and allows for many more options when inserting code or editing text.

    In any case this really needs to be fixed.  In my opinion this is very aggravating to most people trying to use these forums.


    ¯\_(ツ)_/¯


    • Edited by jrv Saturday, September 15, 2012 5:11 PM
    Saturday, September 15, 2012 5:07 PM

Answers

All replies

  • In this particular case, the sequence \" seems to cause the problem, as if the quote is escaped (and therefore ignored). If I remove the trailing backslash in the first quoted string (which breaks the code), the colorization is OK.

    $folderA="y:\sourcefolder" # note NO trailing \
    $folderB="x:\somefolder\*"  # note filemask
    $folderC="z:\targetfolder"
    # try and move all files that match folderB
    dir $folderB | %{move "$folderA$($_.Name)" $folderC -force -whatif}

    There must be other causes, as I've seen the colorization messed up too often for this to be the only problem.


    Richard Mueller - MVP Directory Services

    Saturday, September 15, 2012 6:04 PM
    Moderator
  • Richard - yes sometimes changing almost any character may change the outcome however it should always allow legal syntax. Quotes and single quotes under many circumstances cause the colorization to break.

    Nearly all syntax highlighters that I have worked with work of of teh syntax map fo rthe language.  Thisis published for all languages.  Once we have a normalized syntax the highlighter will always work as expected.  The highlighter used her eseems to work off a fundamental guesswork for all languages.  This has been noted as one problem with things designed by committee.


    ¯\_(ツ)_/¯

    Saturday, September 15, 2012 6:20 PM
  • Multiple bugs in place to fix this. See http://social.msdn.microsoft.com/Forums/en-US/reportabug/thread/094477e8-c725-458d-8410-456f82d3c710

    Thanks!


    Ed Price (a.k.a User Ed), SQL Server Experience Program Manager (Blog, Twitter, Wiki)

    Tuesday, September 25, 2012 9:01 PM
    Owner
  • Yeah Ed!


    ¯\_(ツ)_/¯

    Tuesday, September 25, 2012 10:28 PM