@@ -42,7 +42,7 @@ import Distribution.Client.Types
42
42
import Distribution.FieldGrammar
43
43
( parseFieldGrammar , takeFields )
44
44
import Distribution.Fields
45
- ( ParseResult , Field ( .. ), SectionArg ( .. ), parseFatalFailure , readFields )
45
+ ( ParseResult , parseFatalFailure , readFields )
46
46
import Distribution.PackageDescription.FieldGrammar
47
47
( executableFieldGrammar )
48
48
import Distribution.PackageDescription.PrettyPrint
@@ -83,6 +83,7 @@ import Control.Exception
83
83
( bracket )
84
84
import qualified Data.ByteString.Char8 as BS
85
85
import Data.ByteString.Lazy ()
86
+ import qualified Data.Set as S
86
87
import System.Directory
87
88
( canonicalizePath , doesFileExist , getTemporaryDirectory , removeDirectoryRecursive )
88
89
import System.FilePath
@@ -258,9 +259,8 @@ updateContextAndWriteProjectFile ctx scriptPath scriptExecutable = do
258
259
-- Replace characters which aren't allowed in the executable component name with '_'
259
260
-- Prefix with "cabal-script-" to make it clear to end users that the name may be mangled
260
261
scriptExeName = " cabal-script-" ++ map censor (takeFileName scriptPath)
261
- censor c = case readFields (fromString $ " executable " ++ [c]) of
262
- Right [Section _ [SecArgName _ _] _] -> c
263
- _ -> ' _'
262
+ censor c | c `S.member` ccNamecore = c
263
+ | otherwise = ' _'
264
264
265
265
sourcePackage = fakeProjectSourcePackage projectRoot
266
266
& lSrcpkgDescription . L. condExecutables
@@ -361,3 +361,13 @@ lSrcpkgDescription f s = fmap (\x -> s { srcpkgDescription = x }) (f (srcpkgDesc
361
361
lLocalPackages :: Lens' ProjectBaseContext [PackageSpecifier UnresolvedSourcePackage ]
362
362
lLocalPackages f s = fmap (\ x -> s { localPackages = x }) (f (localPackages s))
363
363
{-# inline lLocalPackages #-}
364
+
365
+ -- Character classes
366
+ -- Transcribed from "templates/Lexer.x"
367
+ ccSpace , ccCtrlchar , ccPrintable , ccSymbol' , ccParen , ccNamecore :: Set Char
368
+ ccSpace = S. fromList " "
369
+ ccCtrlchar = S. fromList $ [chr 0x0 .. chr 0x1f ] ++ [chr 0x7f ]
370
+ ccPrintable = S. fromList [chr 0x0 .. chr 0xff ] S. \\ ccCtrlchar
371
+ ccSymbol' = S. fromList " ,=<>+*&|!$%^@#?/\\ ~"
372
+ ccParen = S. fromList " ()[]"
373
+ ccNamecore = ccPrintable S. \\ S. unions [ccSpace, S. fromList " :\" {}" , ccParen, ccSymbol']
0 commit comments