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'
3434import chromeGetFile from './filesystem/chrome'
3535import firefoxGetFile from './filesystem/firefox'
3636import { userAgent as parsedUA } from '../../common/utils'
37+ import url from 'url'
3738
3839export function getFile ( path ) {
3940 const browserName = parsedUA . browser . name
@@ -75,14 +76,23 @@ export function saveProject(_project) {
7576 UiState . saved ( )
7677}
7778
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+
7888function downloadProject ( project ) {
7989 return exportProject ( project ) . then ( snapshot => {
8090 if ( snapshot ) {
8191 project . snapshot = snapshot
8292 Object . assign ( project , Manager . emitDependencies ( ) )
8393 }
8494 return browser . downloads . download ( {
85- filename : project . name + '.side' ,
95+ filename : sanitizeProjectName ( project . name ) + '.side' ,
8696 url : createBlob (
8797 'application/json' ,
8898 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