From 8c5f89f95c1ec753ad3f69b4c7940bb4028df7c9 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 4 Dec 2017 11:43:09 +0100 Subject: [PATCH] update createNonClashingName --- src/lib/helper.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/lib/helper.js b/src/lib/helper.js index d47e3ac76c..d577643f4a 100644 --- a/src/lib/helper.js +++ b/src/lib/helper.js @@ -9,13 +9,19 @@ module.exports = { var len = data.length return data.slice(0, 5) + '...' + data.slice(len - 5, len) }, - createNonClashingName (path, fileProvider) { + createNonClashingName (name, fileProvider) { var counter = '' - if (path.endsWith('.sol')) path = path.substring(0, path.lastIndexOf('.sol')) - while (fileProvider.exists(path + counter + '.sol')) { + var ext = 'sol' + var reg = /(.*)\.([^.]+)/g + var split = reg.exec(name) + if (split) { + name = split[1] + ext = split[2] + } + while (fileProvider.exists(name + counter + '.' + ext)) { counter = (counter | 0) + 1 } - return path + counter + '.sol' + return name + counter + '.' + ext }, checkSpecialChars (name) { return name.match(/[/:*?"<>\\'|]/) != null