Skip to content

Commit 7b4ef9e

Browse files
author
Akos Kitta
committed
fix: disallow anything but underscore when converting any string to a valid sketch folder name
Signed-off-by: Akos Kitta <[email protected]>
1 parent 4d45515 commit 7b4ef9e

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

Diff for: arduino-ide-extension/src/common/protocol/sketches-service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export namespace Sketch {
205205
const validName = candidate
206206
? candidate
207207
.replace(/^[^0-9a-zA-Z]{1}/g, defaultFallbackFirstChar)
208-
.replace(/[^0-9a-zA-Z_\.-]/g, defaultFallbackChar)
208+
.replace(/[^0-9a-zA-Z_]/g, defaultFallbackChar)
209209
.slice(0, 63)
210210
: defaultSketchFolderName;
211211
if (appendTimestampSuffix) {
@@ -233,7 +233,7 @@ export namespace Sketch {
233233
return candidate
234234
? candidate
235235
.replace(/^[^0-9a-zA-Z]{1}/g, defaultFallbackFirstChar)
236-
.replace(/[^0-9a-zA-Z_\.-]/g, defaultFallbackChar)
236+
.replace(/[^0-9a-zA-Z_]/g, defaultFallbackChar)
237237
.slice(0, 36)
238238
: defaultSketchFolderName;
239239
}

Diff for: arduino-ide-extension/src/test/common/sketches-service.test.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ describe('sketch', () => {
107107
['foo bar', 'foo_bar' + epochSuffix],
108108
['.foobar', '0foobar' + epochSuffix],
109109
['-fooBar', '0fooBar' + epochSuffix],
110+
['foobar.', 'foobar_' + epochSuffix],
111+
['fooBar-', 'fooBar_' + epochSuffix],
112+
['fooBar+', 'fooBar_' + epochSuffix],
110113
['vAlid', 'vAlid' + epochSuffix],
111114
].map(([input, expected]) =>
112115
toMapIt(input, expected, (input: string) =>
@@ -118,23 +121,20 @@ describe('sketch', () => {
118121
describe('toValidCloudSketchFolderName', () => {
119122
[
120123
['sketch', 'sketch'],
121-
[
122-
'slash-and-dot-is-ok+but+no+plus.ino',
123-
'slash-and-dot-is-ok_but_no_plus.ino',
124-
],
124+
['only_underscore-is+ok.ino', 'only_underscore_is_ok_ino'],
125125
['regex++', 'regex__'],
126-
['dots...', 'dots...'],
127-
['.dots...', '0dots...'],
128-
['-dashes---', '0dashes---'],
126+
['dots...', 'dots___'],
127+
['.dots...', '0dots___'],
128+
['-dashes---', '0dashes___'],
129129
['_underscore___', '0underscore___'],
130130
['No Spaces', 'No_Spaces'],
131131
['_startsWithUnderscore', '0startsWithUnderscore'],
132-
['Invalid+Char.ino', 'Invalid_Char.ino'],
132+
['Invalid+Char.ino', 'Invalid_Char_ino'],
133133
['', 'sketch'],
134134
['/', '0'],
135135
[
136-
'//////////////////////////////////////-/',
137-
'0___________________________________',
136+
'/-1////////////////////+//////////////-/',
137+
'0_1_________________________________',
138138
],
139139
['//trash/', '0_trash_'],
140140
[

0 commit comments

Comments
 (0)