Skip to content

Closing round bracket breaks syntax highlighting on ValidatePattern parameter attribute #74

Closed

Description

@TylerLeonhardt

From James Lucktaylor (@jlucktay) on December 4, 2016 16:5

System Details

  • Operating system name and version: Windows 10 Pro, version 1607, build 14393.447
  • VS Code version: 1.7.2
  • PowerShell extension version: 0.7.2
  • Output from $PSVersionTable:
Name                           Value
----                           -----
PSVersion                      5.1.14393.206
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.206
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Issue Description

I am experiencing a problem with syntax highlighting inside a ValidatePattern attribute on a parameter.

The highlighting seems to break if I make use of a closing round bracket ) inside the validation pattern.

In that part of the pattern, I want the URL to optionally have videos/ in it.

Here is the code from the screenshots, to save from having to type it out when reproducing:

$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest

function Convert-UrlForApi {
    param(
        [Parameter(Mandatory=$true)]
        [ValidatePattern('^http:\/\/www.giantbomb.com\/(videos\/)?[a-z0-9\-]+\/[0-9]+-')]
        [ValidateScript({[Uri]::IsWellFormedUriString($($_), [UriKind]::Absolute)})]
        [String]$Url
    )

    if ($Url -match "\/3030\-[0-9]+\/$") {
        return "http://www.giantbomb.com/api/game$($Matches[0])"
    } elseif ($Url -match "\/2300\-[0-9]+\/$") {
        return "http://www.giantbomb.com/api/video$($Matches[0])"
    } else {
        return $null
    }
}

Please see the screenshots below.

The function itself executes fine and works absolutely as expected and desired with the round bracket in place, so it's just the syntax highlighter getting confused about the round bracket inside the pattern string.

Attached Logs

OK without the round bracket

image

Not OK with the round bracket

image

Copied from original issue: PowerShell/vscode-powershell#357

Activity

  1. TylerLeonhardt commented on Apr 6, 2018

    @TylerLeonhardt
    MemberAuthor

    From Tony (@tonylea) on February 21, 2017 13:26

    I've also noticed this issue.

    Using:

    • Windows 10 Pro
    • VS Code version: 1.9.1
    • PowerShell extension version: 0.9.0

    Validate pattern am using: [ValidatePattern("^([0-9a-fA-F]{2}[:-]{0,1}){5}[0-9a-fA-F]{2}$")]

  2. TylerLeonhardt commented on Apr 6, 2018

    @TylerLeonhardt
    MemberAuthor

    From @cantrellj on February 22, 2018 17:56

    Appears to happen in ValidateScript also

    System Details
    Operating system name and version: Windows 10 Pro 10.0.10586.0
    VS Code version: 1.19.3
    PowerShell extension version: 1.6.0
    Output from $PSVersionTable:

    Name                           Value
    ----                           -----
    PSVersion                      5.0.10586.1295
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
    BuildVersion                   10.0.10586.1295
    CLRVersion                     4.0.30319.42000
    WSManStackVersion              3.0
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
    

    image

  3. TylerLeonhardt commented on Apr 6, 2018

    @TylerLeonhardt
    MemberAuthor

    From Keith Hill (@rkeithhill) on February 23, 2018 3:34

    Syntax highlighting is being managed out of the https://GitHub.com/powershell/editorsyntax project. @tylerl0706 Can you move this issue over to that repo?

  4. TylerLeonhardt commented on Apr 6, 2018

    @TylerLeonhardt
    MemberAuthor

    From Garry Hughes (@gazm81) on April 6, 2018 0:6

    This is still an issue in VS code 1.21.1 with PowerShell plugin 1.60.
    Doesn't appear on any other IDE we have tested.

  5. omniomi commented on May 3, 2018

    @omniomi
    Contributor

    This is the same as issue #75, I found a fix and will submit a PR after more testing.

  6. jlucktay commented on May 3, 2018

    @jlucktay

    Nice one, thanks Nick James (@omniomi) !

  7. TylerLeonhardt commented on May 3, 2018

    @TylerLeonhardt
    MemberAuthor

    Nick James (@omniomi) is the man 🎉 💪

  8. omniomi commented on May 21, 2018

    @omniomi
    Contributor

    Fixed by #94

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions