diff --git a/netpyne_ui/netpyne_geppetto.py b/netpyne_ui/netpyne_geppetto.py index 7fa47880..ed75adaa 100644 --- a/netpyne_ui/netpyne_geppetto.py +++ b/netpyne_ui/netpyne_geppetto.py @@ -774,7 +774,8 @@ def doIhaveInstOrSimData(self): return {'haveInstance': out[0], 'haveSimData': out[1]} def rename(self, path, oldValue, newValue): - command = 'sim.rename(self.' + path + ',"' + oldValue + '","' + newValue + '")' + # command = 'sim.rename(self.' + path + ',"' + oldValue + '","' + newValue + '")' + command = f'sim.rename(self.{path}, {oldValue!r}, {newValue!r})' logging.debug('renaming ' + command) eval(command) diff --git a/webapp/Utils.js b/webapp/Utils.js index d53b3021..da39c01c 100644 --- a/webapp/Utils.js +++ b/webapp/Utils.js @@ -155,7 +155,13 @@ const Utils = { return modelFields; }, + asEscapedString (value) { + return value.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + }, + renameKey (path, oldValue, newValue, callback) { + oldValue = oldValue.replace(/\\/g, '\\\\').replace(/"/g, '\\"'); + newValue = newValue.replace(/\\/g, '\\\\').replace(/"/g, '\\"'); this.execPythonMessage(`netpyne_geppetto.rename("${path}","${oldValue}","${newValue}")`) .then((response) => { callback(response, newValue); diff --git a/webapp/components/general/PythonControlledCapability.js b/webapp/components/general/PythonControlledCapability.js index 8a900bdc..66ff0e9b 100644 --- a/webapp/components/general/PythonControlledCapability.js +++ b/webapp/components/general/PythonControlledCapability.js @@ -46,11 +46,14 @@ define((require) => { } connectToPython (componentType, model) { - GeppettoUtils.execPythonMessage(`jupyter_geppetto.ComponentSync(componentType="${componentType}",model="${model}",id="${this.id}").connect()`); + const id = this.id.replace(/\\/g, '\\\\').replace(/"/g, '\\"'); + model = model.replace(/\\/g, '\\\\').replace(/"/g, '\\"'); + GeppettoUtils.execPythonMessage(`jupyter_geppetto.ComponentSync(componentType="${componentType}",model="${model}",id="${id}").connect()`); } disconnectFromPython () { - GeppettoUtils.execPythonMessage(`jupyter_geppetto.remove_component_sync(componentType="${this.state.componentType}",model="${this.id}")`); + const id = this.id.replace(/\\/g, '\\\\').replace(/"/g, '\\"'); + GeppettoUtils.execPythonMessage(`jupyter_geppetto.remove_component_sync(componentType="${this.state.componentType}",model="${id}")`); GEPPETTO.ComponentFactory.removeExistingComponent(this.state.componentType, this); }