File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,13 @@ function sleep(millis) {
1111 } )
1212}
1313
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+
1421class MicroPythonBoard {
1522 constructor ( ) {
1623 this . device = null
@@ -221,7 +228,7 @@ class MicroPythonBoard {
221228 for ( let i = 0 ; i < content . length ; i += 128 ) {
222229 let slice = content . slice ( i , i + 128 )
223230 slice = slice . toString ( )
224- slice = slice . replace ( / " " " / g , `\\"\\"\\"` )
231+ slice = escape_string ( slice )
225232 await this . serial . write ( `w("""${ slice } """)` )
226233 await this . serial . write ( `\x04` )
227234 await sleep ( 100 )
@@ -243,8 +250,7 @@ class MicroPythonBoard {
243250 for ( let i = 0 ; i < content . length ; i += 64 ) {
244251 let slice = content . slice ( i , i + 64 )
245252 slice = slice . toString ( )
246- slice = slice . replace ( / " " " / g, `\\"\\"\\"` )
247- // slice = slice.replace(//g, ``)
253+ slice = escape_string ( slice )
248254 await this . serial . write ( `w("""${ slice } """)\n` )
249255 await this . serial . write ( `\x04` )
250256 await sleep ( 50 )
You can’t perform that action at this time.
0 commit comments