Skip to content

Commit

Permalink
Merge pull request #8 from BolunThompson/bash
Browse files Browse the repository at this point in the history
Ignore binary characters in var file for libbash
  • Loading branch information
angelhof authored Dec 12, 2024
2 parents 71e98e0 + 9cbe342 commit 4c25936
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions sh_expand/env_vars_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ def read_vars_file(var_file_path, bash_version_tuple):
## strings, while this does not
def read_vars_file_new(var_file_path):
vars_dict = {}
with open(var_file_path) as f:
with open(var_file_path, "rb") as f:
for line in f:
# remove newline
line = line[:-1]
line = line[:-1].decode('utf-8', errors='replace')
_, var_type, rest = line.split(" ", maxsplit=2)

## TODO: This doesn't handle associative arrays
Expand Down Expand Up @@ -61,9 +61,9 @@ def read_vars_file_old(var_file_path):
# with open(var_file_path) as f:
# lines = [line.rstrip() for line in f.readlines()]

with open(var_file_path) as f:
with open(var_file_path, "rb") as f:
variable_reading_start_time = datetime.now()
data = f.read()
data = f.read().decode('utf-8', errors='replace')
variable_reading_end_time = datetime.now()
print_time_delta("Variable Reading", variable_reading_start_time, variable_reading_end_time)

Expand Down
1 change: 1 addition & 0 deletions tests/variable_parse/accepted_byte_data.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare -- bin="��"
3 changes: 3 additions & 0 deletions tests/variable_parse/accepted_byte_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"bin": [null, "\ufffd\ufffd"]
}

0 comments on commit 4c25936

Please sign in to comment.