Skip to content

Commit 410fb16

Browse files
authored
Merge pull request disqus#41 from jamesmeador/fixes-regex
Fix regular expressions that cause type parsing to fail
2 parents b47a7f7 + c9c1356 commit 410fb16

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

phabricator/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@
103103
'type': string_types,
104104
}
105105

106-
TYPE_INFO_COMMENT_RE = re.compile(r'\s*\([^)]+\)\s*|,.+$')
106+
TYPE_INFO_COMMENT_RE = re.compile(r'\s*\([^)]+\)\s*$')
107107
TYPE_INFO_SPLITTER_RE = re.compile(r'(\w+(?:<.+>)?)(?:\s+|$)')
108-
TYPE_INFO_RE = re.compile(r'(\w+)(<[^>]+>)?(?:\s+|$)')
108+
TYPE_INFO_RE = re.compile(r'<?(\w+)(<[^>]+>>?)?(?:.+|$)')
109109

110110

111111
def map_param_type(param_type):
@@ -127,7 +127,7 @@ def map_param_type(param_type):
127127
# Handle list of pairs: "optional list<pair<callsign, path>>"
128128
sub_match = TYPE_INFO_RE.match(sub_type)
129129
if sub_match:
130-
sub_type = sub_match.group(0).lower()
130+
sub_type = sub_match.group(1).lower()
131131

132132
return [PARAM_TYPE_MAP.setdefault(sub_type, string_types)]
133133

phabricator/tests/test_phabricator.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,18 @@ def test_validation(self):
159159
with self.assertRaises(ValueError):
160160
self.api.differential.find(query='1', guids='1')
161161

162+
def test_map_param_type(self):
163+
uint = 'uint'
164+
self.assertEqual(phabricator.map_param_type(uint), int)
165+
166+
list_bool = 'list<bool>'
167+
self.assertEqual(phabricator.map_param_type(list_bool), [bool])
168+
169+
list_pair = 'list<pair<callsign, path>>'
170+
self.assertEqual(phabricator.map_param_type(list_pair), [tuple])
171+
172+
complex_list_pair = 'list<pair<string-constant<"gtcm">, string>>'
173+
self.assertEqual(phabricator.map_param_type(complex_list_pair), [tuple])
162174

163175
if __name__ == '__main__':
164176
unittest.main()

0 commit comments

Comments
 (0)