Skip to content

$test:/ - colon is not being parsed correctly on string #192

Description

Environment

  • Editor and Version (VS Code, Atom, Sublime): vscode 1.42.0-insiders
  • Your primary theme: Monokai

Issue Description

From my tests, this seems to only happen if the colon is followed by some sort of special character such as - @ / etc

Screenshots

image

Expected Behavior

It should parse correctly, like this (taken from windows powershell). Notice that the colon is green, since it "belongs" to the variable:
image

Code Samples

$ip = "192.1.1.1"
###not being parsed###
"pi@$ip:/home/pi/PowerShell_IoT/"
"pi@$ip:-home/pi/PowerShell_IoT/"
"pi@$ip:@home/pi/PowerShell_IoT/"
###parsed correctly when without special characters###
"pi@$ip:home/pi/PowerShell_IoT/"
###correct syntax###
"pi@$ip`:/home/pi/PowerShell_IoT/"```

Activity

  1. msftrncs commented on Dec 22, 2019

    @msftrncs
    Contributor

    There might be a little confusion of what should be displayed here.

    $ip: is not a valid variable reference.

    Here is your code on PR #156 when using a theme that highlights invalid constructs in bright red.

    image

    Note the squiggles from PSSA indicating the variable references are invalid.

    Notice that the colon is green, since it "belongs" to the variable:

    But notice that the prompt > is red, indicating that something is wrong with the command.

    The correct syntax is actually:

    "pi@${ip}:/home/pi/PowerShell_IoT/"

    image

  2. DanielSSilva commented on Dec 22, 2019

    @DanielSSilva
    Author

    Yap, I know that it is an invalid reference, but so is $ip:@ (I think).
    Because I don't use PowerShell that much, I forgot that $variable: is reserved for scope, but because it was not highlighted as an error, it took me a while to understand what was wrong.
    So I think that what you showed with a theme that highlights is what's expected. Which theme is that btw?

  3. msftrncs commented on Dec 23, 2019

    @msftrncs
    Contributor

    The theme in my images is a modified Monokai Dimmed, https://github.com/msftrncs/theme-monokai-less-dimmed. Monokai Dimmed does provide an invalid scope.

    What is more important is the work I put in to PR #156 so that the invalid variable reference was scoped as invalid. Currently, the variable constructs in the current repository requires a valid character after the ':' in order to be part of the scope or drive reference, and might not even consider any additional colons as valid at all, so you might have a point there. This appears to be what issue #49 was about. I've been running with PR #156 for so long I've forgotten this was an issue.

    In $ip:@, when contained within an expandable string, only the $ip: would be considered invalid, as the @ would be considered just part of the string. @ is not allowed in a bare variable reference, but is only considered for a splatting operation if it is the first character in a bare-word argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions