Skip to content

Commit

Permalink
Issue 46: _GetParents does not account for comments.
Browse files Browse the repository at this point in the history
Also added 'r' to the regular expression.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=152069446
  • Loading branch information
robankeny authored and Rob Ankeny committed Apr 3, 2017
1 parent 47337aa commit d10959d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def __init__(self, naming_dir=None, naming_file=None, naming_type=None):
self.networks = {}
self.unseen_services = {}
self.unseen_networks = {}
self.port_re = re.compile('(^\d+-\d+|^\d+)\/\w+$|^[\w\d-]+$',
self.port_re = re.compile(r'(^\d+-\d+|^\d+)\/\w+$|^[\w\d-]+$',
re.IGNORECASE|re.DOTALL)
if naming_file and naming_type:
filename = os.path.sep.join([naming_dir, naming_file])
Expand Down Expand Up @@ -195,7 +195,8 @@ def GetIpParents(self, query):
for bp in base_parents:
done = False
for token in self.networks:
if bp in self.networks[token].items:
if bp in [item.split('#')[0].strip() for item in
self.networks[token].items]:
# ignore IPs, only look at token values
if bp[:1].isalpha():
if bp not in recursive_parents:
Expand Down Expand Up @@ -242,7 +243,8 @@ def _GetParents(self, query, query_group):
recursive_parents = []
# collect list of tokens containing query
for token in query_group:
if query in query_group[token].items:
if query in [item.split('#')[0].strip() for item in
query_group[token].items]:
base_parents.append(token)
if not base_parents:
return []
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/naming_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def setUp(self):
networkdata.append('BAR_V6 = ::1/128')
networkdata.append('BAZ = FOO_V6')
networkdata.append(' BAR_V6')
networkdata.append('BING = NET1')
networkdata.append('BING = NET1 # foo')
networkdata.append(' FOO_V6')

self.defs.ParseServiceList(servicedata)
Expand Down

0 comments on commit d10959d

Please sign in to comment.