Skip to content

Commit 15cdeab

Browse files
committed
Restrict the use of the shell setting
- This was added to work around a node-security change on windows, which did not effect other platforms - The `purs ide server` command is executed with globs that should be passed literally, not interpreted by the shell. Path length issues and lack of globstar in the shell used can result in a wrong set of files and thus missing docs/references. This change restricts that shell setting to windows only, as the simplest thing that could possibly work. With any luck cmd.exe will not be able to interpret these globs anyway
1 parent ceee3d5 commit 15cdeab

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

src/IdePurescript/Build.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ import Effect.Exception (catchException)
1818
import Effect.Ref (Ref)
1919
import Effect.Ref as Ref
2020
import Foreign.Object as Object
21-
import IdePurescript.Exec (findBins, getPathVar, whichSync)
21+
import IdePurescript.Exec (findBins, getPathVar, shellSetting, whichSync)
2222
import IdePurescript.PscErrors (PscResult(..), parsePscOutput)
2323
import IdePurescript.PscIdeServer (ErrorLevel(..), Notify)
2424
import Node.Buffer (Buffer)
2525
import Node.Buffer as Buffer
2626
import Node.ChildProcess (ChildProcess)
2727
import Node.ChildProcess as CP
28-
import Node.ChildProcess.Types (Exit(..), enableShell)
28+
import Node.ChildProcess.Types (Exit(..))
2929
import Node.Encoding as Encoding
3030
import Node.Errors.SystemError (toError)
3131
import Node.EventEmitter (on_, once_)
@@ -73,7 +73,7 @@ spawn { command: Command cmd args, directory, useNpmDir } = do
7373
{ path, pathExt: Nothing }
7474
cmd
7575
CP.spawn' cmd' args
76-
(_ { cwd = Just directory, env = env, shell = Just enableShell })
76+
(_ { cwd = Just directory, env = env, shell = shellSetting })
7777

7878
-- Spawn with npm path, "which" call (windows support) and version info gathering
7979
spawnWithVersion ::
@@ -92,7 +92,7 @@ spawnWithVersion { command: Command cmd args, directory, useNpmDir } = do
9292
env
9393
Just <$> CP.spawn' cmdBin args
9494
( _
95-
{ cwd = Just directory, env = Just childEnv, shell = Just enableShell }
95+
{ cwd = Just directory, env = Just childEnv, shell = shellSetting }
9696
)
9797
_ -> pure Nothing
9898
pure { cmdBins, cp }

src/IdePurescript/Exec.purs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@ import Effect (Effect)
1010
import Effect.Aff (Aff)
1111
import Effect.Class (liftEffect)
1212
import Foreign.Object as Object
13-
import Node.ChildProcess.Types (enableShell)
13+
import Node.ChildProcess.Types (Shell, enableShell)
1414
import Node.Path as Path
15-
import Node.Process (getEnv, lookupEnv)
15+
import Node.Platform (Platform(..))
16+
import Node.Process (getEnv, lookupEnv, platform)
1617
import Node.Which (which')
1718
import PscIde.Server (Executable(..), findBins')
1819

20+
shellSetting :: Maybe Shell
21+
shellSetting = case platform of
22+
Just Win32 -> Just enableShell
23+
_ -> Nothing
24+
1925
findBins :: forall a. Either a String -> String -> Aff (Array Executable)
2026
findBins pathVar server = do
2127
env <- liftEffect getEnv
@@ -24,7 +30,7 @@ findBins pathVar server = do
2430
, path: either (const Nothing) Just pathVar
2531
, env: either (const Nothing) (Just <<< flip (Object.insert "PATH") env)
2632
pathVar
27-
, shell: Just enableShell
33+
, shell: shellSetting
2834
}
2935
server
3036

src/IdePurescript/PscIdeServer.purs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ import Data.Tuple (Tuple(..))
2424
import Effect (Effect)
2525
import Effect.Aff (Aff, attempt, try)
2626
import Effect.Class (liftEffect)
27-
import IdePurescript.Exec (findBins, getPathVar)
27+
import IdePurescript.Exec (findBins, getPathVar, shellSetting)
2828
import IdePurescript.PscIde (cwd) as PscIde
2929
import Node.Buffer as Buffer
3030
import Node.ChildProcess (ChildProcess, stderr, stdout)
31-
import Node.ChildProcess.Types (enableShell)
3231
import Node.Encoding (Encoding(..))
3332
import Node.EventEmitter (on_)
3433
import Node.Path (normalize)
@@ -231,7 +230,7 @@ startServer
231230
, source = glob
232231
, logLevel = logLevel
233232
, outputDirectory = outputDirectory
234-
, shell = Just enableShell
233+
, shell = shellSetting
235234
}
236235
)
237236
where

src/LanguageServer/IdePurescript/Server.purs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ import Data.Time.Duration (Milliseconds(..))
1919
import Effect.Aff (Aff, attempt, delay, makeAff)
2020
import Effect.Class (class MonadEffect, liftEffect)
2121
import Foreign (Foreign)
22-
import IdePurescript.Exec (findBins, getPathVar)
22+
import IdePurescript.Exec (findBins, getPathVar, shellSetting)
2323
import IdePurescript.PscIdeServer (ErrorLevel(..), Notify)
2424
import IdePurescript.PscIdeServer as P
2525
import LanguageServer.IdePurescript.Config (ConfigFn)
2626
import LanguageServer.IdePurescript.Config as Config
2727
import LanguageServer.Protocol.Types (Settings)
2828
import Node.Buffer (toString)
2929
import Node.ChildProcess as CP
30-
import Node.ChildProcess.Types (enableShell)
3130
import Node.Encoding (Encoding(..))
3231
import Node.Process (lookupEnv)
3332
import PscIde (load)
@@ -107,7 +106,7 @@ getPackagerPaths enabled binName settings root =
107106
makeAff \cb -> do
108107
void
109108
$ CP.execFile' bin [ "sources" ]
110-
(_ { cwd = Just root, shell = Just enableShell })
109+
(_ { cwd = Just root, shell = shellSetting })
111110
( \{ stdout } -> do
112111
text <- toString UTF8 stdout
113112
cb $ pure $ lines text

0 commit comments

Comments
 (0)