From 5e768c19d01aedba63f0e4a14971b134fd9ac3de Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Sat, 10 Jun 2023 14:39:36 -0700 Subject: [PATCH] Stop modifying the event data in onSerialReceive --- package-lock.json | 4 ++-- package.json | 2 +- repl.js | 8 +++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index aef6e61..532a68a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@adafruit/circuitpython-repl-js", - "version": "1.2.2", + "version": "1.2.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@adafruit/circuitpython-repl-js", - "version": "1.2.2", + "version": "1.2.3", "license": "MIT", "devDependencies": {} } diff --git a/package.json b/package.json index df435dd..0c72781 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "publishConfig": { "registry": "https://npm.pkg.github.com" }, - "version": "1.2.2", + "version": "1.2.3", "description": "A JavaScript Module to help with interfacing to the REPL on CircuitPython Devices over serial", "main": "repl.js", "dependencies": { diff --git a/repl.js b/repl.js index 8986a25..2c292fd 100644 --- a/repl.js +++ b/repl.js @@ -102,15 +102,17 @@ export class REPL { } async onSerialReceive(e) { - // Prepend a partial token if it exists + // We don't want to modify e.data, so we make a copy of it + let data = e.data; + // Prepend a partial token if it exists if (this._partialToken) { - e.data = this._partialToken + e.data; + data = this._partialToken + data; this._partialToken = null; } // Tokenize the larger string and send to the parent - let tokens = this._tokenize(e.data); + let tokens = this._tokenize(data); // Remove any partial tokens and store for the next serial data receive if (tokens.length && this._hasPartialToken(tokens.slice(-1))) {