Use match rather than split

This commit is contained in:
John Firebaugh
2014-05-18 12:35:22 -07:00
parent 22c71bffca
commit f9520362c9

View File

@@ -167,9 +167,9 @@ iD.ui.RawTagEditor = function(context) {
tag = {};
if (kNew && kNew !== kOld) {
var a = _.compact(kNew.split(/^(.*)_(\d+)$/)),
base = a[0],
suffix = (a.length > 1) ? parseInt(a[1]): 1;
var match = kNew.match(/^(.*?)(?:_(\d+))?$/),
base = match[1],
suffix = +(match[2] || 1);
while (tags[kNew]) { // rename key if already in use
kNew = base + '_' + suffix++;
}