Skip to content

Commit 4f5626d

Browse files
authored
Tolerate whitespace between require and terminating ; (#884)
1 parent 09a7c83 commit 4f5626d

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

lib/registrar.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ class Registrar {
2323
this.modifierWhitelist = [];
2424
}
2525

26+
_seekSemiColon(contract, pos) {
27+
const end = pos + 5;
28+
for(pos; pos <= end; pos++) {
29+
if (contract[pos] === ';') break;
30+
}
31+
return pos;
32+
}
33+
2634
/**
2735
* Adds injection point to injection points map
2836
* @param {Object} contract instrumentation target
@@ -441,7 +449,7 @@ class Registrar {
441449
);
442450
this._createInjectionPoint(
443451
contract,
444-
expression.range[1] + 2,
452+
this._seekSemiColon(contract.instrumented, expression.range[1] + 1) + 1,
445453
{
446454
type: 'injectRequirePost',
447455
branchId: contract.branchId,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pragma solidity >=0.8.0 <0.9.0;
2+
3+
contract Test {
4+
function a(uint x) public {
5+
require(true);
6+
require(true) ;
7+
require(true) ;
8+
}
9+
}

test/units/statements.js

+5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ describe('generic statements', () => {
8585
util.report(info.solcOutput.errors);
8686
});
8787

88+
it('should instrument require statements when semi-colon is separated by spaces', () => {
89+
const info = util.instrumentAndCompile('statements/require');
90+
util.report(info.solcOutput.errors);
91+
});
92+
8893
it('should cover an emitted event statement', async function() {
8994
const contract = await util.bootstrapCoverage('statements/emit-coverage', api, this.provider);
9095
coverage.addContract(contract.instrumented, util.filePath);

0 commit comments

Comments
 (0)