Skip to content

Commit eb69125

Browse files
Bug fixes with appending variable list
1 parent 37bcffa commit eb69125

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

bashparser.egg-info/PKG-INFO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.1
22
Name: bashparser
3-
Version: 0.6
3+
Version: 0.7
44
Summary: A framework for manipulating and analysing bash scripts
55
Home-page: https://github.com/BlankCanvasStudio/bashparse
66
Author: Spencer Stingley

bashparser/test/test_variable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def test_update_variable_list(self):
114114
self.assertTrue({'a':['3']} == new_var_list)
115115
node = bashparser.parse('a=4')[0]
116116
new_var_list = update_variable_list(node, new_var_list)
117-
self.assertTrue({'a':['3', '4']} == new_var_list)
117+
self.assertTrue({'a':['4']} == new_var_list)
118118

119119

120120
def test_update_var_list_with_for_loop(self):

bashparser/variables.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def apply_fn(node, var_list):
161161
""" We need to treat a variable and for loop seperately because a string in a for loop is actually an array """
162162
if node.kind == 'assignment':
163163
name, value = node.word.split('=', maxsplit=1)
164-
var_list = add_variable_to_list(var_list, name, value)
164+
var_list = add_variable_to_list(var_list, name, value, append=False)
165165
elif node.kind == 'for':
166166
var_list = update_var_list_with_for_loop(node, var_list)
167167
return CONT
@@ -170,7 +170,7 @@ def apply_fn(node, var_list):
170170
return var_list
171171

172172

173-
def add_variable_to_list(var_list, name, values):
173+
def add_variable_to_list(var_list, name, values, append=True):
174174
""" (variable dict, name, value) Adds the corresponding name and value to dictionary. If name exists in
175175
the dictionary, the value is added. Prevents bugs with use of the var_list """
176176

@@ -182,7 +182,7 @@ def add_variable_to_list(var_list, name, values):
182182
for i, val in enumerate(values):
183183
if type(val) is not str and type(val) is not bashlex.ast.node: values[i] = str(val)
184184

185-
if name in var_list:
185+
if name in var_list and append:
186186
for val in values:
187187
if val not in var_list[name]:
188188
var_list[name] += [ val ]

0 commit comments

Comments
 (0)