Commit 3d72f842 authored by lianahus's avatar lianahus Committed by Liana Husikyan

fixes for corner cases

parent 102be890
import { ViewPlugin } from '@remixproject/engine-web' import { ViewPlugin } from '@remixproject/engine-web'
import { canUseWorker, urlFromVersion } from '../compiler/compiler-utils' 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 yo = require('yo-yo')
var async = require('async') var async = require('async')
...@@ -440,7 +440,10 @@ module.exports = class TestTab extends ViewPlugin { ...@@ -440,7 +440,10 @@ module.exports = class TestTab extends ViewPlugin {
handleCreateFolder () { handleCreateFolder () {
this.inputPath.value = this.trimTestDirInput(this.inputPath.value) 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 if (this.inputPath.value === '') this.inputPath.value = this.defaultPath
this.inputPath.value = path
this.testTabLogic.generateTestFolder(this.inputPath.value) this.testTabLogic.generateTestFolder(this.inputPath.value)
this.createTestFolder.disabled = true this.createTestFolder.disabled = true
this.updateGenerateFileAction().disabled = false this.updateGenerateFileAction().disabled = false
...@@ -603,7 +606,8 @@ module.exports = class TestTab extends ViewPlugin { ...@@ -603,7 +606,8 @@ module.exports = class TestTab extends ViewPlugin {
async handleTestDirInput (e) { async handleTestDirInput (e) {
let testDirInput = this.trimTestDirInput(this.inputPath.value) let testDirInput = this.trimTestDirInput(this.inputPath.value)
testDirInput = helper.removeMultipleSlashes(testDirInput) testDirInput = removeMultipleSlashes(testDirInput)
if (testDirInput !== '/') testDirInput = removeTrailingSlashes(testDirInput)
if (e.key === 'Enter') { if (e.key === 'Enter') {
this.inputPath.value = testDirInput this.inputPath.value = testDirInput
if (await this.testTabLogic.pathExists(testDirInput)) { if (await this.testTabLogic.pathExists(testDirInput)) {
...@@ -614,8 +618,8 @@ module.exports = class TestTab extends ViewPlugin { ...@@ -614,8 +618,8 @@ module.exports = class TestTab extends ViewPlugin {
} }
if (testDirInput) { if (testDirInput) {
if (testDirInput.endsWith('/')) { if (testDirInput.endsWith('/') && testDirInput !== '/') {
testDirInput = helper.removeTrailingSlashes(testDirInput) testDirInput = removeTrailingSlashes(testDirInput)
if (this.testTabLogic.currentPath === testDirInput.substr(0, testDirInput.length - 1)) { if (this.testTabLogic.currentPath === testDirInput.substr(0, testDirInput.length - 1)) {
this.createTestFolder.disabled = true this.createTestFolder.disabled = true
this.updateGenerateFileAction().disabled = true this.updateGenerateFileAction().disabled = true
...@@ -639,7 +643,7 @@ module.exports = class TestTab extends ViewPlugin { ...@@ -639,7 +643,7 @@ module.exports = class TestTab extends ViewPlugin {
} }
async handleEnter (e) { 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 (this.createTestFolder.disabled) {
if (await this.testTabLogic.pathExists(this.inputPath.value)) { if (await this.testTabLogic.pathExists(this.inputPath.value)) {
this.testTabLogic.setCurrentPath(this.inputPath.value) this.testTabLogic.setCurrentPath(this.inputPath.value)
......
...@@ -10,7 +10,7 @@ class TestTabLogic { ...@@ -10,7 +10,7 @@ class TestTabLogic {
setCurrentPath (path) { setCurrentPath (path) {
if (path.indexOf('/') === 0) return if (path.indexOf('/') === 0) return
this.currentPath = path this.currentPath = helper.removeMultipleSlashes(helper.removeTrailingSlashes(path))
} }
generateTestFolder (path) { generateTestFolder (path) {
......
...@@ -105,8 +105,8 @@ module.exports = { ...@@ -105,8 +105,8 @@ module.exports = {
return this.is0XPrefixed(hash) && /^[0-9a-fA-F]{64}$/.test(hexValue) return this.is0XPrefixed(hash) && /^[0-9a-fA-F]{64}$/.test(hexValue)
}, },
removeTrailingSlashes (text) { removeTrailingSlashes (text) {
// Single or consecutive leading slashes: // Remove single or consecutive trailing slashes
return text.replace(/^\/+/g, '') return text.replace(/\/+$/g, '')
}, },
removeMultipleSlashes (text) { removeMultipleSlashes (text) {
// Replace consecutive slashes with '/' // Replace consecutive slashes with '/'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment