Skip to content

Commit a15dcb9

Browse files
committed
netpyne-24 Escape variables that are transmitted to python
1 parent e09838e commit a15dcb9

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

netpyne_ui/netpyne_geppetto.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,8 @@ def doIhaveInstOrSimData(self):
774774
return {'haveInstance': out[0], 'haveSimData': out[1]}
775775

776776
def rename(self, path, oldValue, newValue):
777-
command = 'sim.rename(self.' + path + ',"' + oldValue + '","' + newValue + '")'
777+
# command = 'sim.rename(self.' + path + ',"' + oldValue + '","' + newValue + '")'
778+
command = f'sim.rename(self.{path}, {oldValue!r}, {newValue!r})'
778779
logging.debug('renaming ' + command)
779780

780781
eval(command)

webapp/Utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ const Utils = {
156156
},
157157

158158
renameKey (path, oldValue, newValue, callback) {
159+
oldValue = oldValue.replace(/"/g, '\\"');
160+
newValue = newValue.replace(/"/g, '\\"');
159161
this.execPythonMessage(`netpyne_geppetto.rename("${path}","${oldValue}","${newValue}")`)
160162
.then((response) => {
161163
callback(response, newValue);

webapp/components/general/PythonControlledCapability.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,14 @@ define((require) => {
4646
}
4747

4848
connectToPython (componentType, model) {
49-
GeppettoUtils.execPythonMessage(`jupyter_geppetto.ComponentSync(componentType="${componentType}",model="${model}",id="${this.id}").connect()`);
49+
const id = this.id.replace(/"/g, '\\"');
50+
model = model.replace(/"/g, '\\"');
51+
GeppettoUtils.execPythonMessage(`jupyter_geppetto.ComponentSync(componentType="${componentType}",model="${model}",id="${id}").connect()`);
5052
}
5153

5254
disconnectFromPython () {
53-
GeppettoUtils.execPythonMessage(`jupyter_geppetto.remove_component_sync(componentType="${this.state.componentType}",model="${this.id}")`);
55+
const id = this.id.replace(/"/g, '\\"');
56+
GeppettoUtils.execPythonMessage(`jupyter_geppetto.remove_component_sync(componentType="${this.state.componentType}",model="${id}")`);
5457
GEPPETTO.ComponentFactory.removeExistingComponent(this.state.componentType, this);
5558
}
5659

@@ -150,7 +153,7 @@ define((require) => {
150153
if ((this.state.model !== nextProps.model) && (nextProps.model !== undefined)) {
151154
this.setState({ model: nextProps.model });
152155
}
153-
}
156+
}
154157
}
155158

156159
componentDidUpdate (prevProps, prevState) {

0 commit comments

Comments
 (0)