diff --git a/apps/remix-ide/src/app/tabs/test-tab.js b/apps/remix-ide/src/app/tabs/test-tab.js index f2e9ece175..6103429985 100644 --- a/apps/remix-ide/src/app/tabs/test-tab.js +++ b/apps/remix-ide/src/app/tabs/test-tab.js @@ -1,6 +1,6 @@ import { ViewPlugin } from '@remixproject/engine-web' import { canUseWorker, urlFromVersion } from '../compiler/compiler-utils' -import * as helper from '../../lib/helper' +import { removeMultipleSlashes, removeTrailingSlashes } from '../../lib/helper' var yo = require('yo-yo') var async = require('async') @@ -440,7 +440,10 @@ module.exports = class TestTab extends ViewPlugin { handleCreateFolder () { this.inputPath.value = this.trimTestDirInput(this.inputPath.value) + let path = removeMultipleSlashes(this.inputPath.value) + if (path !== '/') path = removeTrailingSlashes(path) if (this.inputPath.value === '') this.inputPath.value = this.defaultPath + this.inputPath.value = path this.testTabLogic.generateTestFolder(this.inputPath.value) this.createTestFolder.disabled = true this.updateGenerateFileAction().disabled = false @@ -603,7 +606,8 @@ module.exports = class TestTab extends ViewPlugin { async handleTestDirInput (e) { let testDirInput = this.trimTestDirInput(this.inputPath.value) - testDirInput = helper.removeMultipleSlashes(testDirInput) + testDirInput = removeMultipleSlashes(testDirInput) + if (testDirInput !== '/') testDirInput = removeTrailingSlashes(testDirInput) if (e.key === 'Enter') { this.inputPath.value = testDirInput if (await this.testTabLogic.pathExists(testDirInput)) { @@ -614,8 +618,8 @@ module.exports = class TestTab extends ViewPlugin { } if (testDirInput) { - if (testDirInput.endsWith('/')) { - testDirInput = helper.removeTrailingSlashes(testDirInput) + if (testDirInput.endsWith('/') && testDirInput !== '/') { + testDirInput = removeTrailingSlashes(testDirInput) if (this.testTabLogic.currentPath === testDirInput.substr(0, testDirInput.length - 1)) { this.createTestFolder.disabled = true this.updateGenerateFileAction().disabled = true @@ -639,7 +643,7 @@ module.exports = class TestTab extends ViewPlugin { } async handleEnter (e) { - this.inputPath.value = helper.removeMultipleSlashes(this.trimTestDirInput(this.inputPath.value)) + this.inputPath.value = removeMultipleSlashes(this.trimTestDirInput(this.inputPath.value)) if (this.createTestFolder.disabled) { if (await this.testTabLogic.pathExists(this.inputPath.value)) { this.testTabLogic.setCurrentPath(this.inputPath.value) diff --git a/apps/remix-ide/src/app/tabs/testTab/testTab.js b/apps/remix-ide/src/app/tabs/testTab/testTab.js index e1fcf2d09e..7b6e1fd4fc 100644 --- a/apps/remix-ide/src/app/tabs/testTab/testTab.js +++ b/apps/remix-ide/src/app/tabs/testTab/testTab.js @@ -10,7 +10,7 @@ class TestTabLogic { setCurrentPath (path) { if (path.indexOf('/') === 0) return - this.currentPath = path + this.currentPath = helper.removeMultipleSlashes(helper.removeTrailingSlashes(path)) } generateTestFolder (path) { diff --git a/apps/remix-ide/src/lib/helper.js b/apps/remix-ide/src/lib/helper.js index f352803282..8f0640544c 100644 --- a/apps/remix-ide/src/lib/helper.js +++ b/apps/remix-ide/src/lib/helper.js @@ -105,8 +105,8 @@ module.exports = { return this.is0XPrefixed(hash) && /^[0-9a-fA-F]{64}$/.test(hexValue) }, removeTrailingSlashes (text) { - // Single or consecutive leading slashes: - return text.replace(/^\/+/g, '') + // Remove single or consecutive trailing slashes + return text.replace(/\/+$/g, '') }, removeMultipleSlashes (text) { // Replace consecutive slashes with '/'