Skip to content

Commit c9c1356

Browse files
committed
Fixes disqus#37,disqus#39: Fix Regex bugs causing incorrect type detection and validation failures
1 parent 838398b commit c9c1356

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
@@ -139,6 +139,18 @@ def test_validation(self):
139139
with self.assertRaises(ValueError):
140140
self.api.differential.find(query='1', guids='1')
141141

142+
def test_map_param_type(self):
143+
uint = 'uint'
144+
self.assertEqual(phabricator.map_param_type(uint), int)
145+
146+
list_bool = 'list<bool>'
147+
self.assertEqual(phabricator.map_param_type(list_bool), [bool])
148+
149+
list_pair = 'list<pair<callsign, path>>'
150+
self.assertEqual(phabricator.map_param_type(list_pair), [tuple])
151+
152+
complex_list_pair = 'list<pair<string-constant<"gtcm">, string>>'
153+
self.assertEqual(phabricator.map_param_type(complex_list_pair), [tuple])
142154

143155
if __name__ == '__main__':
144156
unittest.main()

0 commit comments

Comments
 (0)