Skip to content

Commit 24431b8

Browse files
authored
Merge pull request #198 from ethereum/check-callback
Raise error if invalid import callback is supplied
2 parents 9fbe261 + eeae488 commit 24431b8

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

test/package.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,22 @@ tape('Compilation', function (t) {
177177
st.end();
178178
});
179179

180+
t.test('lazy-loading callback fails properly (with invalid callback)', function (st) {
181+
if (semver.lt(solc.semver(), '0.2.1')) {
182+
st.skip('Not supported by solc <0.2.1');
183+
st.end();
184+
return;
185+
}
186+
187+
var input = {
188+
'cont.sol': 'import "lib.sol"; contract x { function g() { L.f(); } }'
189+
};
190+
st.throws(function () {
191+
solc.compile({sources: input}, 0, "this isn't a callback");
192+
}, /Invalid callback specified./);
193+
st.end();
194+
});
195+
180196
t.test('file import without lazy-loading callback fails properly', function (st) {
181197
if (semver.lt(solc.semver(), '0.2.1')) {
182198
st.skip('Not supported by solc <0.2.1');

wrapper.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var assert = require('assert');
12
var translate = require('./translate.js');
23
var linker = require('./linker.js');
34
var requireFromString = require('require-from-string');
@@ -20,6 +21,7 @@ function setupMethods (soljson) {
2021
soljson.setValue(ptr, buffer, '*');
2122
};
2223
var wrapCallback = function (callback) {
24+
assert(typeof callback === 'function', 'Invalid callback specified.');
2325
return function (path, contents, error) {
2426
var result = callback(soljson.Pointer_stringify(path));
2527
if (typeof result.contents === 'string') {
@@ -97,6 +99,10 @@ function setupMethods (soljson) {
9799
});
98100
}
99101

102+
if (readCallback !== null && typeof readCallback !== 'function') {
103+
return formatFatalError('Invalid import callback supplied');
104+
}
105+
100106
input = JSON.parse(input);
101107

102108
if (input['language'] !== 'Solidity') {

0 commit comments

Comments
 (0)