diff options
author | Ben Gamari <ben@smart-cactus.org> | 2020-02-05 09:27:00 -0500 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-03-10 02:05:42 -0400 |
commit | 70b5077820a0859d22edd29885b62eef3c363058 (patch) | |
tree | 6dbcd4c5302096478ba64e8d0befedc9200933f1 | |
parent | 5b62781336aff0007aa5fde261c3028a82543a09 (diff) | |
download | haskell-70b5077820a0859d22edd29885b62eef3c363058.tar.gz |
SysTools: Ensure that error parser can handle absolute paths on Windows
This fixes #17786, where the error parser fails to correctly handle the
drive name in absolute Windows paths.
Unfortunately I couldn't find a satisfactory way to test this.
-rw-r--r-- | compiler/main/SysTools/Process.hs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/compiler/main/SysTools/Process.hs b/compiler/main/SysTools/Process.hs index b36b53c5e5..aa5d6617d3 100644 --- a/compiler/main/SysTools/Process.hs +++ b/compiler/main/SysTools/Process.hs @@ -344,10 +344,21 @@ parseError s0 = case breakColon s0 of Nothing -> Nothing Nothing -> Nothing +-- | Break a line of an error message into a filename and the rest of the line, +-- taking care to ignore colons in Windows drive letters (as noted in #17786). +-- For instance, +-- +-- * @"hi.c: ABCD"@ is mapped to @Just ("hi.c", "ABCD")@ +-- * @"C:\hi.c: ABCD"@ is mapped to @Just ("C:\hi.c", "ABCD")@ breakColon :: String -> Maybe (String, String) -breakColon xs = case break (':' ==) xs of - (ys, _:zs) -> Just (ys, zs) - _ -> Nothing +breakColon = go [] + where + -- Don't break on Windows drive letters (e.g. @C:\@ or @C:/@) + go accum (':':'\\':rest) = go ('\\':':':accum) rest + go accum (':':'/':rest) = go ('/':':':accum) rest + go accum (':':rest) = Just (reverse accum, rest) + go accum (c:rest) = go (c:accum) rest + go _accum [] = Nothing breakIntColon :: String -> Maybe (Int, String) breakIntColon xs = case break (':' ==) xs of |