Skip to content

Commit

Permalink
[#239][#249] Parse quoted git ls-files
Browse files Browse the repository at this point in the history
Problem: When a file name contains unusual characters, its output line
in git ls-files is quoted and Xrefcheck parses the file name wrong.

Solution: If a git ls-files output line starts with a double quote, use
the String Read instance for parsing it.
  • Loading branch information
aeqz committed Jan 24, 2023
1 parent 999518b commit 3507b6b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Xrefcheck/Scan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ readDirectoryWith
-> CanonicalPath
-> IO [(CanonicalPath, a)]
readDirectoryWith mode config scanner root = do
relativeFiles <- L.lines <$> getFiles
relativeFiles <- fmap filePath . L.lines <$> getFiles
canonicalFiles <- mapM (root </) relativeFiles
traverse scanFile $ filter (not . isIgnored) canonicalFiles

Expand All @@ -197,6 +197,11 @@ readDirectoryWith mode config scanner root = do
getUntrackedFiles = readCreateProcess
(shell "git ls-files --others --exclude-standard"){cwd = Just $ unCanonicalPath root} ""

filePath :: String -> FilePath
filePath = \case
quoted@('\"' : _) -> fromMaybe quoted $ readMaybe quoted
unquoted -> unquoted

scanFile :: CanonicalPath -> IO (CanonicalPath, a)
scanFile c = (c,) <$> scanner c

Expand Down

0 comments on commit 3507b6b

Please sign in to comment.