mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Disallow store names that are not A-Za-z0-9_
This commit is contained in:
parent
d9d15e41c7
commit
75c29f1cb7
@ -161,6 +161,7 @@
|
|||||||
"error-module-not-loaded": "'__module__' could not be loaded",
|
"error-module-not-loaded": "'__module__' could not be loaded",
|
||||||
"error-loading-module": "Error loading context module '__module__': __message__ ",
|
"error-loading-module": "Error loading context module '__module__': __message__ ",
|
||||||
"error-module-not-defined": "'module' is not defined in '__storage__' of settings.contextStorage",
|
"error-module-not-defined": "'module' is not defined in '__storage__' of settings.contextStorage",
|
||||||
|
"error-invalid-module-name": "Invalid context store name: '__name__'",
|
||||||
"error-invalid-default-module": "Invalid storage '__storage__' is specified as a default storage",
|
"error-invalid-default-module": "Invalid storage '__storage__' is specified as a default storage",
|
||||||
"error-use-undefined-storage": "Undefined storage '__storage__' is specified"
|
"error-use-undefined-storage": "Undefined storage '__storage__' is specified"
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,9 @@ function load() {
|
|||||||
if (pluginName === "_") {
|
if (pluginName === "_") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!/^[a-zA-Z0-9_]+$/.test(pluginName)) {
|
||||||
|
return reject(new Error(log._("context.error-invalid-module-name", {name:pluginName})));
|
||||||
|
}
|
||||||
|
|
||||||
// Check if this is setting the 'default' context to be a named plugin
|
// Check if this is setting the 'default' context to be a named plugin
|
||||||
if (pluginName === "default" && typeof plugins[pluginName] === "string") {
|
if (pluginName === "default" && typeof plugins[pluginName] === "string") {
|
||||||
|
@ -292,26 +292,6 @@ describe('context', function() {
|
|||||||
Context.init({contextStorage:{file:{module:"localfilesystem",config:{dir:resourcesDir}}}});
|
Context.init({contextStorage:{file:{module:"localfilesystem",config:{dir:resourcesDir}}}});
|
||||||
Context.load();
|
Context.load();
|
||||||
});
|
});
|
||||||
it('should accept special storage name', function(done) {
|
|
||||||
Context.init({
|
|
||||||
contextStorage:{
|
|
||||||
"#%&":{module:testPlugin},
|
|
||||||
\u3042:{module:testPlugin},
|
|
||||||
1:{module:testPlugin},
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Context.load().then(function(){
|
|
||||||
var context = Context.get("1","flow");
|
|
||||||
var cb = function(){done("An error occurred")}
|
|
||||||
context.set("sign","sign1","#%&",cb);
|
|
||||||
context.set("file","file2","\u3042",cb);
|
|
||||||
context.set("num","num3","1",cb);
|
|
||||||
stubSet.calledWithExactly("1:flow","sign","sign1",cb).should.be.true();
|
|
||||||
stubSet.calledWithExactly("1:flow","file","file2",cb).should.be.true();
|
|
||||||
stubSet.calledWithExactly("1:flow","num","num3",cb).should.be.true();
|
|
||||||
done();
|
|
||||||
}).catch(done);
|
|
||||||
});
|
|
||||||
it('should ignore reserved storage name `_`', function(done) {
|
it('should ignore reserved storage name `_`', function(done) {
|
||||||
Context.init({contextStorage:{_:{module:testPlugin}}});
|
Context.init({contextStorage:{_:{module:testPlugin}}});
|
||||||
Context.load().then(function(){
|
Context.load().then(function(){
|
||||||
@ -326,6 +306,15 @@ describe('context', function() {
|
|||||||
done();
|
done();
|
||||||
}).catch(done);
|
}).catch(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should fail when using invalid store name', function(done) {
|
||||||
|
Context.init({contextStorage:{'Invalid name':"noexist"}});
|
||||||
|
Context.load().then(function(){
|
||||||
|
done("An error was not thrown");
|
||||||
|
}).catch(function(){
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
it('should fail when using invalid default context', function(done) {
|
it('should fail when using invalid default context', function(done) {
|
||||||
Context.init({contextStorage:{default:"noexist"}});
|
Context.init({contextStorage:{default:"noexist"}});
|
||||||
Context.load().then(function(){
|
Context.load().then(function(){
|
||||||
|
Loading…
Reference in New Issue
Block a user