style: Escape quotes and backslashes in usePeripheralWithSide method for safe Lua string interpolation

This commit is contained in:
MayaTheShy
2026-02-20 02:50:14 -05:00
parent a68ddd843f
commit 997c64c40b

View File

@@ -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 : ''})`);
}
/**