@@ -11,6 +11,13 @@ function sleep(millis) {
11
11
} )
12
12
}
13
13
14
+ function escape_string ( string ) {
15
+ string = string . replace ( / " " " / g, `\\"\\"\\"` )
16
+ string = string . replace ( / \' / g, `\\'` )
17
+ string = string . replace ( / \" / g, `\\"` )
18
+ return string
19
+ }
20
+
14
21
class MicroPythonBoard {
15
22
constructor ( ) {
16
23
this . device = null
@@ -244,7 +251,7 @@ class MicroPythonBoard {
244
251
for ( let i = 0 ; i < content . length ; i += 128 ) {
245
252
let slice = content . slice ( i , i + 128 )
246
253
slice = slice . toString ( )
247
- slice = slice . replace ( / " " " / g , `\\"\\"\\"` )
254
+ slice = escape_string ( slice )
248
255
await this . serial . write ( `w("""${ slice } """)` )
249
256
await this . serial . write ( `\x04` )
250
257
await sleep ( 100 )
@@ -266,8 +273,7 @@ class MicroPythonBoard {
266
273
for ( let i = 0 ; i < content . length ; i += 64 ) {
267
274
let slice = content . slice ( i , i + 64 )
268
275
slice = slice . toString ( )
269
- slice = slice . replace ( / " " " / g, `\\"\\"\\"` )
270
- // slice = slice.replace(//g, ``)
276
+ slice = escape_string ( slice )
271
277
await this . serial . write ( `w("""${ slice } """)\n` )
272
278
await this . serial . write ( `\x04` )
273
279
await sleep ( 50 )
0 commit comments