diff --git a/libs/remix-solidity/src/compiler/compiler-utils.ts b/libs/remix-solidity/src/compiler/compiler-utils.ts index da3bc487b3..7e19ae7d8a 100644 --- a/libs/remix-solidity/src/compiler/compiler-utils.ts +++ b/libs/remix-solidity/src/compiler/compiler-utils.ts @@ -12,9 +12,21 @@ export const pathToURL = {} * @param version is the version of compiler with or without 'soljson-v' prefix and .js postfix */ export function urlFromVersion (version) { - if (!version.startsWith('soljson-v')) version = 'soljson-v' + version - if (!version.endsWith('.js')) version = version + '.js' - return `${pathToURL[version]}/${version}` + let url + if (version === 'builtin') { + let location: string | Location = window.document.location + let path = location.pathname + if (!path.startsWith('/')) path = '/' + path + location = `${location.protocol}//${location.host}${path}assets/js` + if (location.endsWith('index.html')) location = location.substring(0, location.length - 10) + if (!location.endsWith('/')) location += '/' + url = `${location}soljson.js` + } else { + if (!version.startsWith('soljson-v')) version = 'soljson-v' + version + if (!version.endsWith('.js')) version = version + '.js' + url = `${pathToURL[version]}/${version}` + } + return url } /** diff --git a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx index 9469121adf..80b1004ab6 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx @@ -333,19 +333,15 @@ export const CompilerContainer = (props: CompilerContainerProps) => { updateCurrentVersion(selectedVersion) url = customUrl api.setParameters({ version: selectedVersion }) - } else if (selectedVersion === 'builtin') { - let location: string | Location = window.document.location - let path = location.pathname - if (!path.startsWith('/')) path = '/' + path - location = `${location.protocol}//${location.host}${path}assets/js` - if (location.endsWith('index.html')) location = location.substring(0, location.length - 10) - if (!location.endsWith('/')) location += '/' - url = location + 'soljson.js' } else { - if (selectedVersion.indexOf('soljson') !== 0 || helper.checkSpecialChars(selectedVersion)) { - return console.log('loading ' + selectedVersion + ' not allowed') + if (helper.checkSpecialChars(selectedVersion)) { + return console.log('loading ' + selectedVersion + ' not allowed, special chars not allowed.') + } + if (selectedVersion === 'builtin' || selectedVersion.indexOf('soljson') === 0) { + url = urlFromVersion(selectedVersion) + } else { + return console.log('loading ' + selectedVersion + ' not allowed, version should start with "soljson"') } - url = `${urlFromVersion(selectedVersion)}` } // Workers cannot load js on "file:"-URLs and we get a