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

properly parse code to extract import paths instead of relying on regular expressions #62

Open
0xteddybear opened this issue Nov 26, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@0xteddybear
Copy link
Contributor

0xteddybear commented Nov 26, 2024

In order to rewrite the paths in import statements, we are trying to find the import paths via naive regular expressions like /^\s*import /i, which work for most cases but are insufficient to parse all valid solidity productions.

This causes both false positives, exemplified by the current implementation modifying imports which are alone in their line but inside multiline comments:

/*  
import '../../../node_modules/some-package/Contract.sol';
*/

And false negatives, such as failing to detect a second import statement in a single line:

import 'foo/Foo.sol'; import 'foo/Bar.sol';

The way to properly fix this is to use a 3-rd party parser, such as solidity-parser or solc-typed-ast to extract the locations of the import statements and their path attributes.

@0xteddybear 0xteddybear added the bug Something isn't working label Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant