Skip to content

Commit 55e84db

Browse files
authored
Merge pull request #556 from ethereum/handle-colons-in-file-names-on-0.4.10
Fix crash on 0.4.10 when the file name contains a colon
2 parents 8920105 + 7c78d4c commit 55e84db

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

test/compiler.js

+71
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const assert = require('assert');
12
const tape = require('tape');
23
const semver = require('semver');
34
const solc = require('../index.js');
@@ -9,6 +10,16 @@ var noRemoteVersions = (process.argv.indexOf('--no-remote-versions') >= 0);
910
function runTests (solc, versionText) {
1011
console.log(`Running tests with ${versionText} ${solc.version()}`);
1112

13+
function resplitFileNameOnFirstColon (fileName, contractName) {
14+
assert(!contractName.includes(':'));
15+
16+
let contractNameComponents = fileName.split(':');
17+
const truncatedFileName = contractNameComponents.shift();
18+
contractNameComponents.push(contractName);
19+
20+
return [truncatedFileName, contractNameComponents.join(':')];
21+
}
22+
1223
function getBytecode (output, fileName, contractName) {
1324
try {
1425
var outputContract;
@@ -29,6 +40,9 @@ function runTests (solc, versionText) {
2940
if (semver.lt(solc.semver(), '0.4.9')) {
3041
outputFile = output.contracts[''];
3142
} else {
43+
if (semver.gt(solc.semver(), '0.4.10') && semver.lt(solc.semver(), '0.4.20')) {
44+
[fileName, contractName] = resplitFileNameOnFirstColon(fileName, contractName);
45+
}
3246
outputFile = output.contracts[fileName];
3347
}
3448
return outputFile[contractName]['evm']['bytecode']['object'];
@@ -43,6 +57,9 @@ function runTests (solc, versionText) {
4357
if (semver.lt(solc.semver(), '0.4.9')) {
4458
outputFile = output.contracts[''];
4559
} else {
60+
if (semver.gt(solc.semver(), '0.4.10') && semver.gt(solc.semver(), '0.4.20')) {
61+
[fileName, contractName] = resplitFileNameOnFirstColon(fileName, contractName);
62+
}
4663
outputFile = output.contracts[fileName];
4764
}
4865
return outputFile[contractName]['evm']['gasEstimates'];
@@ -757,6 +774,56 @@ function runTests (solc, versionText) {
757774
}
758775
st.end();
759776
});
777+
778+
t.test('compiling standard JSON (file names containing symbols)', function (st) {
779+
var input = {
780+
'language': 'Solidity',
781+
'settings': {
782+
'outputSelection': {
783+
'*': {
784+
'*': ['evm.bytecode']
785+
}
786+
}
787+
},
788+
'sources': {
789+
'!@#$%^&*()_+-=[]{}\\|"\';:~`<>,.?/': {
790+
'content': 'contract C {}'
791+
}
792+
}
793+
};
794+
795+
var output = JSON.parse(solc.compile(JSON.stringify(input)));
796+
st.ok(expectNoError(output));
797+
var C = getBytecodeStandard(output, '!@#$%^&*()_+-=[]{}\\|"\';:~`<>,.?/', 'C');
798+
st.ok(typeof C === 'string');
799+
st.ok(C.length > 0);
800+
st.end();
801+
});
802+
803+
t.test('compiling standard JSON (file names containing multiple semicolons)', function (st) {
804+
var input = {
805+
'language': 'Solidity',
806+
'settings': {
807+
'outputSelection': {
808+
'*': {
809+
'*': ['evm.bytecode']
810+
}
811+
}
812+
},
813+
'sources': {
814+
'a:b:c:d:e:f:G.sol': {
815+
'content': 'contract G {}'
816+
}
817+
}
818+
};
819+
820+
var output = JSON.parse(solc.compile(JSON.stringify(input)));
821+
st.ok(expectNoError(output));
822+
var G = getBytecodeStandard(output, 'a:b:c:d:e:f:G.sol', 'G');
823+
st.ok(typeof G === 'string');
824+
st.ok(G.length > 0);
825+
st.end();
826+
});
760827
});
761828
});
762829

@@ -810,8 +877,12 @@ if (!noRemoteVersions) {
810877
'v0.2.1+commit.91a6b35',
811878
'v0.3.6+commit.3fc68da',
812879
'v0.4.0+commit.acd334c9',
880+
'v0.4.9+commit.364da425',
881+
'v0.4.10+commit.f0d539ae',
813882
'v0.4.11+commit.68ef5810',
814883
'v0.4.12+commit.194ff033',
884+
'v0.4.19+commit.c4cbbb05',
885+
'v0.4.20+commit.3155dd80',
815886
'v0.4.26+commit.4563c3fc'
816887
];
817888
for (var version in versions) {

translate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function translateJsonCompilerOutput (output, libraries) {
7878
ret['contracts'] = {};
7979
for (var contract in output['contracts']) {
8080
// Split name first, can be `contract`, `:contract` or `filename:contract`
81-
var tmp = contract.match(/^(([^:]*):)?([^:]+)$/);
81+
var tmp = contract.match(/^((.*):)?([^:]+)$/);
8282
if (tmp.length !== 4) {
8383
// Force abort
8484
return null;

0 commit comments

Comments
 (0)