Comments you submit will be routed for moderation. If you have an account, please log in first.
Modify

Ticket #3884 (closed defect: fixed)

Opened 7 years ago

Last modified 7 years ago

gcovr fails when the path includes regex special characters

Reported by: cody@… Owned by: jdsiiro
Priority: normal Milestone:
Component: gcovr Version:
Keywords: Cc:

Description

I.e. a path with "g++" in it causes:

Traceback (most recent call last):
  File "/home/hudson/bin/gcovr", line 619, in <module>
    options.filter = re.compile(options.root.replace("\\","\\\\"))
  File "/usr/lib/python2.6/re.py", line 190, in compile
    return _compile(pattern, flags)
  File "/usr/lib/python2.6/re.py", line 245, in _compile
    raise error, v # invalid expression
sre_constants.error: multiple repeat

If I try to work around that by running gcovr -f `pwd | sed 's/\+/\\\+/g'` it works, but then the output has the two first characters truncated (presumably because it trimmed the path by the number of characters in the filter, but counted the two escaping slashes.

Attachments

Change History

comment:1 Changed 7 years ago by cody@…

I've currently worked around it with this diff:

--- gcovr       2011-01-05 16:46:54.000000000 -0700
+++ gcovr-old   2011-01-05 16:44:39.000000000 -0700
@@ -605,13 +605,8 @@
 #
 for i in range(0,len(options.exclude)):
     options.exclude[i] = re.compile(options.exclude[i])
-filter_pattern_size = 0
 if options.filter is not None:
     options.filter = re.compile(options.filter)
-    if options.filter.pattern[-1] == os.sep:
-        filter_pattern_size = len(options.filter.pattern)
-    else:
-        filter_pattern_size = len(options.filter.pattern) + len(os.sep)
 elif options.root is not None:
     #if options.root[0] != os.sep:
     #    dir=os.getcwd()+os.sep+options.root
@@ -620,9 +615,15 @@
     #else:
     #    options.root=os.path.abspath(options.root)
     options.root=os.path.abspath(options.root)
-    filter_pattern_size = len(options.root) + len(os.sep)
     #print "HERE",options.root
-    options.filter = re.compile(re.escape(options.root))
+    options.filter = re.compile(options.root.replace("\\","\\\\"))
+if options.filter is not None:
+    if options.filter.pattern[-1] == os.sep:
+        filter_pattern_size = len(options.filter.pattern)
+    else:
+        filter_pattern_size = len(options.filter.pattern) + len(os.sep)
+else:
+    filter_pattern_size = 0
 #
 # Get data files
 #

Note using re.escape rather than doing a replace on \ for
. Also, I set filter_pattern_size to the original length of the string, before converting to a regex. The one thing I'm not sure about is setting filter_pattern_size when an actual filter was passed. It seems to me that since the actual filter could be an arbitrary regex, that it would be impossible to get an absolute count of the number of characters to truncate, so either the filter needs to be re-applied on output, or when using a filter no truncation should occur at all.

comment:2 Changed 7 years ago by jdsiiro

Referenced in changeset [2556]:

Overhaul of the --root / --filter logic. This should resolve the issue raised in #3884, along with the more general filter issue raised in comment:ticket:3884:1

comment:3 Changed 7 years ago by jdsiiro

Referenced in changeset [2557]:

Addressing special case mentioned in comment:ticket:3884:1: do not truncate the reported file name if the filter does not start matching at the beginning of the string.

comment:4 Changed 7 years ago by jdsiiro

  • Status changed from new to closed
  • Resolution set to fixed

Fixed in [2556:2557].

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.