Skip to content

The content of a quoted string is being parsed when it shouldn't be. #4870

Closed

Description

Steps to reproduce

 "OK" | grep -E "[^:]"

Expected behavior

Should output

OK

Actual behavior

On macOs outputs an error:

Cannot find drive. A drive with the name '[^' does not exist.
At line:1 char:1
+ "OK" |  grep -E '[^:]+'
+ ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: ([^:String) [], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound

On Windows (with grep) outputs the expected OK.

Comment

Compare with

 "OK" | Tee-Object "[^:]"

on windows which returns the identical error message.

 "OK" | Select-String -pattern "[^:]"

works correctly on both platforms.

Environment data

> $PSVersionTable
Name                           Value                                                                                   
----                           -----                                                                                   
PSVersion                      6.0.0-beta                                                                              
PSEdition                      Core                                                                                    
GitCommitId                    v6.0.0-beta.7                                                                           
OS                             Darwin 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-37...
Platform                       Unix                                                                                    
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                 
PSRemotingProtocolVersion      2.3                                                                                     
SerializationVersion           1.1.0.1                                                                                 
WSManStackVersion              3.0      

Activity

  1. markekraus commented on Sep 20, 2017

    @markekraus
    Contributor

    It appears to happen with any string that fits the pattern

    .+:[^ `]*[*?\[\]].*

    I can repro this on

    Name                           Value
    ----                           -----
    PSVersion                      6.0.0-beta
    PSEdition                      Core
    GitCommitId                    v6.0.0-beta.7
    OS                             Linux 4.4.0-93-generic #116-Ubuntu SMP Fri Au...
    Platform                       Unix
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
    WSManStackVersion              3.0
    

    Other examples:

    /bin/echo 'a:]'
    /bin/echo "a:]"
    /bin/echo "a:["
    /bin/echo "a:*"
    /bin/echo "a:?"
    
    $string = 'a:]'
    /bin/echo $string
    /bin/echo "$string"
    /bin/echo $($string)
    /bin/echo ($string)
    /bin/echo @($string)
    
    /bin/echo 'a:llllllll]llll'
    /bin/echo 'a:lllllllllllllllll]'

    These all produce the same results.

    $Error[0] | Fl *  -force
    
    PSMessageDetails      :
    Exception             : System.Management.Automation.DriveNotFoundException: Cannot find drive. A drive with the name 'a' does not exist.
                               at System.Management.Automation.SessionStateInternal.GetDrive(String name, Boolean automount)
                               at System.Management.Automation.SessionStateInternal.AutomountBuiltInDrive(String name)
                               at System.Management.Automation.SessionStateInternal.GetDrive(String name, Boolean automount)
                               at System.Management.Automation.SessionStateInternal.GetDrive(String name)
                               at System.Management.Automation.DriveManagementIntrinsics.Get(String driveName)
                               at System.Management.Automation.LocationGlobber.GetDriveRootRelativePathFromPSPath(String path, CmdletProviderContext context, Boolean
                            escapeCurrentLocation, PSDriveInfo& workingDriveForPath, CmdletProvider& providerInstance)
                               at System.Management.Automation.LocationGlobber.GetProviderPath(String path, CmdletProviderContext context, Boolean isTrusted, ProviderInfo&
                            provider, PSDriveInfo& drive)
                               at System.Management.Automation.LocationGlobber.GetProviderPath(String path, CmdletProviderContext context, ProviderInfo& provider, PSDriveInfo&
                            drive)
                               at System.Management.Automation.LocationGlobber.GetGlobbedProviderPathsFromMonadPath(String path, Boolean allowNonexistingPaths,
                            CmdletProviderContext context, ProviderInfo& provider, CmdletProvider& providerInstance)
                               at System.Management.Automation.SessionStateInternal.GetChildItems(String path, Boolean recurse, UInt32 depth, CmdletProviderContext context)
                               at System.Management.Automation.SessionStateInternal.GetChildItems(String[] paths, Boolean recurse, UInt32 depth, Boolean force, Boolean
                            literalPath)
                               at System.Management.Automation.ChildItemCmdletProviderIntrinsics.Get(String path, Boolean recurse)
                               at System.Management.Automation.NativeCommandParameterBinder.appendOneNativeArgument(ExecutionContext context, Object obj, Char separator, Boolean
                            sawVerbatimArgumentMarker)
                               at System.Management.Automation.NativeCommandParameterBinder.BindParameters(Collection`1 parameters)
                               at System.Management.Automation.NativeCommandParameterBinderController.BindParameters(Collection`1 parameters)
                               at System.Management.Automation.NativeCommandProcessor.Prepare(IDictionary psDefaultParameterValues)
                               at System.Management.Automation.CommandProcessorBase.DoPrepare(IDictionary psDefaultParameterValues)
                               at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream)
                               at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
                            --- End of stack trace from previous location where exception was thrown ---
                               at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                               at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
                               at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements,
                            CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)
                               at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
                               at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
    TargetObject          : a
    CategoryInfo          : ObjectNotFound: (a:String) [], DriveNotFoundException
    FullyQualifiedErrorId : DriveNotFound
    ErrorDetails          :
    InvocationInfo        : System.Management.Automation.InvocationInfo
    ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
    PipelineIterationInfo : {}
    

    These all work fine though:

    /bin/echo ":]"
    /bin/echo 'a]'
    /bin/echo 'a:'
    /bin/echo 'a:a'
    /bin/echo 'aa]'
    /bin/echo 'aa]a'
    /bin/echo 'a:aa'
    Start-Process -FilePath /bin/echo -ArgumentList 'a:]'

    and

    /bin/echo 'a:`]'
    

    Prints

    a:`]
    
  2. BrucePay commented on Sep 20, 2017

    @BrucePay
    Collaborator

    This is caused by #3931 which should be fixed in the next beta.

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