From 997c64c40b7c00eaa295cd7242f6cee11d80b567 Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Fri, 20 Feb 2026 02:50:14 -0500 Subject: [PATCH] style: Escape quotes and backslashes in usePeripheralWithSide method for safe Lua string interpolation --- server/Turtle.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/Turtle.js b/server/Turtle.js index a83a833..1f9a3bd 100644 --- a/server/Turtle.js +++ b/server/Turtle.js @@ -807,13 +807,15 @@ export class Turtle extends EventEmitter { * Use a peripheral method by side */ async usePeripheralWithSide(side, method, ...args) { + const safeSide = side.replace(/\\/g, '\\\\').replace(/"/g, '\\"'); + const safeMethod = method.replace(/\\/g, '\\\\').replace(/"/g, '\\"'); const argsStr = args.map(a => { if (a === null) return 'nil'; - if (typeof a === 'string') return `"${a}"`; + if (typeof a === 'string') return `"${a.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`; return String(a); }).join(', '); - return this.exec(`return peripheral.call("${side}", "${method}"${argsStr ? ', ' + argsStr : ''})`); + return this.exec(`return peripheral.call("${safeSide}", "${safeMethod}"${argsStr ? ', ' + argsStr : ''})`); } /**