File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed
packages/selenium-ide/src/neo Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ import Manager from '../../plugin/manager'
34
34
import chromeGetFile from './filesystem/chrome'
35
35
import firefoxGetFile from './filesystem/firefox'
36
36
import { userAgent as parsedUA } from '../../common/utils'
37
+ import url from 'url'
37
38
38
39
export function getFile ( path ) {
39
40
const browserName = parsedUA . browser . name
@@ -75,14 +76,23 @@ export function saveProject(_project) {
75
76
UiState . saved ( )
76
77
}
77
78
79
+ export function sanitizeProjectName ( projectName ) {
80
+ let name = projectName
81
+ if ( name . startsWith ( 'http' ) ) {
82
+ return url . parse ( projectName ) . host
83
+ } else {
84
+ return name . replace ( / ( [ ^ a - z 0 - 9 . _ - ] + ) / gi, '' )
85
+ }
86
+ }
87
+
78
88
function downloadProject ( project ) {
79
89
return exportProject ( project ) . then ( snapshot => {
80
90
if ( snapshot ) {
81
91
project . snapshot = snapshot
82
92
Object . assign ( project , Manager . emitDependencies ( ) )
83
93
}
84
94
return browser . downloads . download ( {
85
- filename : project . name + '.side' ,
95
+ filename : sanitizeProjectName ( project . name ) + '.side' ,
86
96
url : createBlob (
87
97
'application/json' ,
88
98
beautify ( JSON . stringify ( project ) , { indent_size : 2 } )
Original file line number Diff line number Diff line change
1
+ import { sanitizeProjectName } from '../../IO/filesystem'
2
+
3
+ describe ( 'filesystem' , ( ) => {
4
+ describe ( 'save' , ( ) => {
5
+ describe ( 'filename' , ( ) => {
6
+ it ( 'allows alpha-numeric characters' , ( ) => {
7
+ const input = 'asdf1234'
8
+ expect ( sanitizeProjectName ( input ) ) . toEqual ( input )
9
+ } )
10
+ it ( 'allows limited special characters' , ( ) => {
11
+ let input = 'asdf-1234'
12
+ expect ( sanitizeProjectName ( input ) ) . toEqual ( input )
13
+ input = 'asdf_1234'
14
+ expect ( sanitizeProjectName ( input ) ) . toEqual ( input )
15
+ input = 'asdf.1234'
16
+ expect ( sanitizeProjectName ( input ) ) . toEqual ( input )
17
+ input = 'asdf 1234'
18
+ expect ( sanitizeProjectName ( input ) ) . toEqual ( input )
19
+ } )
20
+ it ( 'ignores illegal filesystem characters' , ( ) => {
21
+ const input = 'blah:/blah'
22
+ expect ( sanitizeProjectName ( input ) ) . toEqual ( 'blahblah' )
23
+ } )
24
+ it ( 'with URI returns the root' , ( ) => {
25
+ const input = 'http://a.b.com'
26
+ expect ( sanitizeProjectName ( input ) ) . toEqual ( 'a.b.com' )
27
+ } )
28
+ } )
29
+ } )
30
+ } )
You can’t perform that action at this time.
0 commit comments