Ticket #115 (closed defect: invalid)

Opened 6 years ago

Last modified 5 years ago

showFilePath/showToken dodgy characters

Reported by: igloo Owned by:
Priority: normal Milestone:
Component: Cabal library Version: 1.1.6
Severity: normal Keywords:
Cc: Difficulty: normal
GHC Version: 6.6 Platform: Linux

Description

showFilePath/showToken are defined with:

showFilePath :: FilePath -> Doc
showFilePath = showToken

showToken :: String -> Doc
showToken str
 | not (any dodgy str) &&
   not (null str)       = text str
 | otherwise            = text (show str)
  where dodgy c = isSpace c || c == ','

The dodgy function looks a bit incomplete to me; I'd have expected \ and " at least to be in there too, or better yet for non-dodgy characters to be what are listed.

Change History

Changed 5 years ago by duncan

Actually I think this is ok.

So showFilePath and parseFilePathQ are the two inverses that are used by many fields.

parseFilePathQ = parseTokenQ

parseTokenQ = parseReadS <++ munch1 (\x -> not (isSpace x) && x /= ',')

parseReadS is a parser that uses Read, which for a String of course means parsing an ordinary Haskell string in quotes with escapes etc.

The alternative then, if it is not surrounded in quotes, is a token is a bunch of characters that is not a space or ','. " and \ would be interpreted as it, eg foo"bar\"baz would all be one token. So correspondingly, the only characters that would cause a problem when pretty printing are spaces and ',', in which case we should use the standard show for String.

So for example this means that '\' in Windows paths does not need to be escaped unless you use "C:\\Foo\Bar" in Haskell string syntax.

Changed 5 years ago by duncan

  • status changed from new to closed
  • resolution set to invalid
Note: See TracTickets for help on using tickets.