Skip to content

Commit

Permalink
fix(FileAnalyzer): update regex to find top level keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
RyuuGan committed Sep 10, 2019
1 parent 1bcd6ea commit c85a443
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/fileAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class FileAnalyzer {
*
*/
analyzeExports(contents: string): FileAnalyzerExportsResult[] {
const exportRegex = /(contract|library|interface)\s+([a-zA-Z_$][a-zA-Z_$0-9]*)\s*([\s\S]*?)\{/g;
const exportRegex = /(contract|library|interface)\s+([a-zA-Z_$][a-zA-Z_$0-9]*)\s*([^"]*?)\{/g;
const results = [];
let group: RegExpExecArray;
while ((group = exportRegex.exec(contents))) {
Expand Down
66 changes: 66 additions & 0 deletions test/compiled/ReservedWordsInString.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
pragma solidity ^0.5.0;


contract Ownable {
address public owner;

function Ownable() {
owner = msg.sender;
}

modifier onlyOwner() {
require(msg.sender == owner);
_;
}

function transferOwnership(address newOwner) onlyOwner {
if (newOwner != address(0)) {
owner = newOwner;
}
}

}

contract Manager is Ownable {
function mintSupply(address src20, address swmAccount, uint256 swmValue, uint256 src20Value)
onlyOwner
external
returns (bool)
{
require(swmAccount != address(0), "SWM account is zero");
require(swmValue != 0, "SWM value is zero");
require(src20Value != 0, "SRC20 value is zero");
require(_registry[src20].owner != address(0), "SRC20 token contract not registered");

_registry[src20].stake = _registry[src20].stake.add(swmValue);
_registry[src20]._swm = swmValue;
_registry[src20]._src = src20Value;

require(_swmERC20.transferFrom(swmAccount, address(this), swmValue));
require(ISRC20Managed(src20).mint(_registry[src20].owner, src20Value));

emit SRC20SupplyMinted(src20, swmAccount, swmValue, src20Value);

return true;
}

function incStake(address src20, address swmAccount, uint256 swmValue)
external
onlyTokenOwner(src20)
returns (bool)
{
require(swmAccount != address(0), "SWM account is zero");
require(swmValue != 0, "SWM value is zero");
require(_registry[src20].owner != address(0), "SRC20 token contract not registered");
require(_registry[src20]._swm != 0, "Token not minted");

_registry[src20].stake = _registry[src20].stake.add(swmValue);

require(_swmERC20.transferFrom(swmAccount, address(this), swmValue));
require(ISRC20Managed(src20).mint(_registry[src20].owner, _calcTokens(src20, swmValue)));

emit SRC20StakeIncreased(src20, swmAccount, swmValue);

return true;
}
}
47 changes: 47 additions & 0 deletions test/contracts/ReservedWordsInString.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
pragma solidity ^0.5.0;

import "./imports/ownable.sol";

contract Manager is Ownable {
function mintSupply(address src20, address swmAccount, uint256 swmValue, uint256 src20Value)
onlyOwner
external
returns (bool)
{
require(swmAccount != address(0), "SWM account is zero");
require(swmValue != 0, "SWM value is zero");
require(src20Value != 0, "SRC20 value is zero");
require(_registry[src20].owner != address(0), "SRC20 token contract not registered");

_registry[src20].stake = _registry[src20].stake.add(swmValue);
_registry[src20]._swm = swmValue;
_registry[src20]._src = src20Value;

require(_swmERC20.transferFrom(swmAccount, address(this), swmValue));
require(ISRC20Managed(src20).mint(_registry[src20].owner, src20Value));

emit SRC20SupplyMinted(src20, swmAccount, swmValue, src20Value);

return true;
}

function incStake(address src20, address swmAccount, uint256 swmValue)
external
onlyTokenOwner(src20)
returns (bool)
{
require(swmAccount != address(0), "SWM account is zero");
require(swmValue != 0, "SWM value is zero");
require(_registry[src20].owner != address(0), "SRC20 token contract not registered");
require(_registry[src20]._swm != 0, "Token not minted");

_registry[src20].stake = _registry[src20].stake.add(swmValue);

require(_swmERC20.transferFrom(swmAccount, address(this), swmValue));
require(ISRC20Managed(src20).mint(_registry[src20].owner, _calcTokens(src20, swmValue)));

emit SRC20StakeIncreased(src20, swmAccount, swmValue);

return true;
}
}
4 changes: 4 additions & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ describe('Solidity Merger', () => {
const result = await merge(file);
assertWithFile(result, 'LocalImports.sol');
});

it('should not find keywords in strings', async () => {
await testFile('ReservedWordsInString');
});
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"importHelpers": false,
"target": "es6",
"module": "commonjs",
"typeRoots": ["node_modules/@types"],
Expand Down

0 comments on commit c85a443

Please sign in to comment.