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

[WIP] Fix source mapping where utf8 char length != byte length #252

Merged
merged 2 commits into from
May 21, 2019
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
10 changes: 6 additions & 4 deletions slither/core/source_mapping/source_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def _compute_line(source_code, start, length):

Not done in an efficient way
"""
source_code = source_code.encode('utf-8')
total_length = len(source_code)
source_code = source_code.splitlines(True)
counter = 0
Expand All @@ -29,17 +30,18 @@ def _compute_line(source_code, start, length):
ending_column = None
while counter < total_length:
# Determine the length of the line, and advance the line number
lineLength = len(source_code[i])
line_content = source_code[i]
line_length = len(line_content)
i = i + 1

# Determine our column numbers.
if starting_column is None and counter + lineLength > start:
if starting_column is None and counter + line_length > start:
starting_column = (start - counter) + 1
if starting_column is not None and ending_column is None and counter + lineLength > start + length:
if starting_column is not None and ending_column is None and counter + line_length > start + length:
ending_column = ((start + length) - counter) + 1

# Advance the current position counter, and determine line numbers.
counter += lineLength
counter += line_length
if counter > start:
lines.append(i)

Expand Down
22 changes: 22 additions & 0 deletions tests/source_mapping.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
contract A{

// ëëëëëëëëëëëëë这这这这这这这这这这

address unused;


address unused2;


// ই এই এই এইই এই এই এইই এই এই এই

address unused3;


address unused4;

// 这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这
address used;


}