Skip to content

Commit 2c4cc6e

Browse files
committed
Refuse to override builtin file type
Arguments of { type: 'file' } are handled specially by strong-remoting and don't go through the usual TypeConverter path. This causes problems in LoopBack applications with a model called "File", which registers a type converter for "file" (the name is case insensitive). In this commit, we are modifying TypeRegistry to throw an error when the caller attempts to override the built-in "file" type.
1 parent bd047c8 commit 2c4cc6e

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/type-registry.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ TypeRegistry.prototype.registerType = function(typeName, converter) {
3232

3333
typeName = typeName.toLowerCase();
3434

35+
if (typeName === 'file') {
36+
throw new Error(g.f('Cannot override built-in "{{file}}" type.'));
37+
}
38+
3539
if (typeName in this._types) {
3640
if (this._options.warnWhenOverridingType !== false)
3741
g.warn('Warning: overriding remoting type %s', typeName);

test/type-registry.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var expect = require('chai').expect;
2+
var TypeRegistry = require('../lib/type-registry');
3+
4+
describe('TypeRegistry', function() {
5+
var registry;
6+
beforeEach(function() {
7+
registry = new TypeRegistry();
8+
});
9+
10+
it('refuses to override built-in file type', function() {
11+
expect(function() {
12+
registry.registerType('File', {
13+
fromTypedValue: function() {},
14+
fromSloppyValue: function() {},
15+
validate: function() {},
16+
});
17+
}).to.throw(/file/);
18+
});
19+
});

0 commit comments

Comments
 (0)