Skip to contentSkip to conversation

Make prune_suffix prune a suffix

PATCH New andre.rosa 1 participant 2 messages Apr 6, 2019 1 message not in the archive

lore
Share & tools
lore

andre.rosa

author
#1 lore raw

PATCH 1/1 Make prune_suffix prune a suffix

In reply to a message not in the archive

From: Andre Rosa <[email protected]>

... instead of replacing a substring that could happen more than once and not only when it ends with it.

lib/bb/utils.py +2 -2
@@ -722,8 +722,8 @@ def prune_suffix(var, suffixes, d):
     # See if var ends with any of the suffixes listed and
     # remove it if found
     for suffix in suffixes:
-        if var.endswith(suffix):
-            return var.replace(suffix, "")
+        if suffix and var.endswith(suffix):
+            return var[:-len(suffix)]
     return var
 
 def mkdirhier(directory):

--
2.20.1

author
#2 lore raw

PATCH 1/1 Make prune_suffix prune a suffix

In reply to a message not in the archive

From: Andre Rosa <[email protected]>

... instead of replacing a substring that could happen more than once and not only when it ends with it.

lib/bb/utils.py +2 -2
@@ -722,8 +722,8 @@ def prune_suffix(var, suffixes, d):
     # See if var ends with any of the suffixes listed and
     # remove it if found
     for suffix in suffixes:
-        if var.endswith(suffix):
-            return var.replace(suffix, "")
+        if suffix and var.endswith(suffix):
+            return var[:-len(suffix)]
     return var
 
 def mkdirhier(directory):

--
2.20.1