Skip to content

Commit

Permalink
Remove platform condition. And handle when special chars are in the dir.
Browse files Browse the repository at this point in the history
  • Loading branch information
sainthkh committed Mar 3, 2020
1 parent 2f98ae1 commit 49f4172
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
6 changes: 1 addition & 5 deletions packages/server/lib/util/escape_filename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ const percentRe = /%/g
const questionRe = /\?/g

export function escapeFilenameInUrl (url: string) {
let paths = url.split('/')

// escape valid file name characters that cannot be used in URL
paths[paths.length - 1] = (_.last<string>(paths) || '')
return url
.replace(percentRe, '%25') // %
.replace(ampersandRe, '%26') // &
.replace(questionRe, '%3F') // ? -> it's only valid in Linux

return paths.join('/')
}
30 changes: 15 additions & 15 deletions packages/server/test/unit/project_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,25 +707,25 @@ This option will not have an effect in Some-other-name. Tests that rely on web s
})
})

if (process.platform !== 'win32') {
// ? is tested here because it's valid in Unix/Linux, but invalid in Windows
// https://gist.github.com/doctaphred/d01d05291546186941e1b7ddc02034d3
it('escapes ?', function () {
const filePath = path.join(__dirname, '../support/fixtures/projects/todos/tests/sub/a?.spec.js')
// ? is invalid in Windows, but it can be tested here
// because it's a unit test and doesn't check the existence of files
it('escapes ?', function () {
const todosSpec = path.join(this.todosPath, 'tests/sub/a?.spec.js')

fs.writeFileSync(filePath, '')
return this.project.getSpecUrl(todosSpec)
.then((str) => {
expect(str).to.eq('http://localhost:8888/__/#/tests/integration/sub/a%3F.spec.js')
})
})

const todosSpec = path.join(this.todosPath, 'tests/sub/a?.spec.js')
it('escapes %, &, ? in the url dir', function () {
const todosSpec = path.join(this.todosPath, 'tests/s%&?ub/a.spec.js')

return this.project.getSpecUrl(todosSpec)
.then((str) => {
expect(str).to.eq('http://localhost:8888/__/#/tests/integration/sub/a%3F.spec.js')
})
.then(() => {
fs.unlinkSync(filePath)
})
return this.project.getSpecUrl(todosSpec)
.then((str) => {
expect(str).to.eq('http://localhost:8888/__/#/tests/integration/s%25%26%3Fub/a.spec.js')
})
}
})

it('returns __all spec url', function () {
return this.project.getSpecUrl()
Expand Down

0 comments on commit 49f4172

Please sign in to comment.