covr icon indicating copy to clipboard operation
covr copied to clipboard

`parse_gcov` assumes that produced source file names are escaped regular expressions

Open hsloot opened this issue 3 years ago • 1 comments

The function parse_gcov tries to skip all files for which source_file is not below root package_path. It does that by using a regular expression.

https://github.com/r-lib/covr/blob/ebf0e7fc215ef91aeeb43ffcbe945e116e6e0187/R/compiled.R#L14

However, rex::regex assumes that the given expression is already an escaped regular expression. That might not be always the case - MacOS is allowing almost all Unicode characters in filenames. In my case, a parent folder contains a "+" (that, unfortunately, cannot be changed).

The effects might vary, but I guess in most cases, the files are simply ignored such that no reports on compiled files are returned.

It should be able to solve this by replacing the relevant expression with

grepl(rex::rex(start, rex::regex(paste0(rex::escape(package_path), collapse = "|"))), source_file)

Possible link to #448.

hsloot avatar Dec 12 '20 16:12 hsloot

Yes, your fix looks correct, would you be interested in submitting a pull request to fix this?

jimhester avatar Dec 14 '20 13:12 jimhester