Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow strings with "{" as modifier arguments #480

Merged
merged 1 commit into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions lib/registrar.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,28 @@ class Registrar {
* @param {Object} expression AST node
*/
functionDeclaration(contract, expression) {
const startContract = contract.instrumented.slice(0, expression.range[0]);
let start = 0;

// It's possible functions will have modifiers that take string args
// which contains an open curly brace. Skip ahead...
if (expression.modifiers && expression.modifiers.length){
for (let modifier of expression.modifiers ){
if (modifier.range[1] > start){
start = modifier.range[1];
}
}
} else {
start = expression.range[0];
}

const startContract = contract.instrumented.slice(0, start);
const startline = ( startContract.match(/\n/g) || [] ).length + 1;
const startcol = expression.range[0] - startContract.lastIndexOf('\n') - 1;
const startcol = start - startContract.lastIndexOf('\n') - 1;

const endlineDelta = contract.instrumented.slice(expression.range[0]).indexOf('{');
const endlineDelta = contract.instrumented.slice(start).indexOf('{');
const functionDefinition = contract.instrumented.slice(
expression.range[0],
expression.range[0] + endlineDelta
start,
start + endlineDelta
);
const endline = startline + (functionDefinition.match(/\n/g) || []).length;
const endcol = functionDefinition.length - functionDefinition.lastIndexOf('\n');
Expand All @@ -118,7 +132,7 @@ class Registrar {

this._createInjectionPoint(
contract,
expression.range[0] + endlineDelta + 1,
start + endlineDelta + 1,
{
type: 'injectFunction',
fnId: contract.fnId,
Expand Down
8 changes: 7 additions & 1 deletion test/sources/solidity/contracts/statements/interpolation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ contract Interpolated {
}
}

contract Test is Interpolated("abc{defg}"){
contract TestA is Interpolated("abc{defg}"){
function a(uint x) public {
uint y = x;
}
}

contract TestB is Interpolated {
constructor(uint x) public Interpolated("abc{defg}") {
uint y = x;
}
}
2 changes: 1 addition & 1 deletion test/units/statements.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('generic statements', () => {
util.report(info.solcOutput.errors);
})

it('should compile a base contract contructor with a string arg containing "{"', ()=> {
it('should compile base contract contructors with string args containing "{"', ()=> {
const info = util.instrumentAndCompile('statements/interpolation');
util.report(info.solcOutput.errors);
})
Expand Down