#42 Limit newVersion's re.sub to a single replacement
Merged 5 years ago by ngompa. Opened 5 years ago by jistone.
jistone/rpmdevtools py3.7-re.sub  into  master

file modified
+2 -2
@@ -134,13 +134,13 @@ 

              original = self.lines[i]

              if self.lines[i].lower().startswith('version:'):

                  self.lines[i] = re.sub(

-                     r'[^: \t]*$', v, self.lines[i].rstrip()) + '\n'

+                     r'[^: \t]*$', v, self.lines[i].rstrip(), count=1) + '\n'

                  changed = changed or self.lines[i] != original

              elif self.lines[i].lower().startswith('release:'):

                  # split and reconstruct to preserve whitespace

                  split = re.split(r':', self.lines[i].rstrip())

                  self.lines[i] = split[0] + ':' + \

-                     re.sub(r'[^ \t]*$', r, split[1]) + '\n'

+                     re.sub(r'[^ \t]*$', r, split[1], count=1) + '\n'

                  changed = changed or self.lines[i] != original

  

          return changed

Python 3.7 changed re.sub to replace empty matches next to a previous
non-empty match, which caused SpecFile.newVersion to double its
replacements. We can use count=1 to limit this.

ref: https://bugs.python.org/issue32308

Fixes #41

Pull-Request has been merged by ngompa

5 years ago
Metadata