Skip to content

Commit 89851f4

Browse files
committed
Fix case when we have two same prefixes in the name
1 parent c2d0718 commit 89851f4

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

nameparser/parser.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ class HumanName(object):
3636
3737
Instantiation assigns to ``full_name``, and assignment to
3838
:py:attr:`full_name` triggers :py:func:`parse_full_name`. After parsing the
39-
name, these instance attributes are available. Alternatively, you can pass
39+
name, these instance attributes are available. Alternatively, you can pass
4040
any of the instance attributes to the constructor method and skip the parsing
41-
process. If any of the the instance attributes are passed to the constructor
42-
as keywords, :py:func:`parse_full_name` will not be performed.
41+
process. If any of the the instance attributes are passed to the constructor
42+
as keywords, :py:func:`parse_full_name` will not be performed.
4343
4444
**HumanName Instance Attributes**
4545
@@ -536,9 +536,9 @@ def parse_nicknames(self):
536536
Loops through 3 :py:data:`~nameparser.config.regexes.REGEXES`;
537537
`quoted_word`, `double_quotes` and `parenthesis`.
538538
"""
539-
539+
540540
empty_re = re.compile("")
541-
541+
542542
re_quoted_word = self.C.regexes.quoted_word or empty_re
543543
re_double_quotes = self.C.regexes.double_quotes or empty_re
544544
re_parenthesis = self.C.regexes.parenthesis or empty_re
@@ -906,7 +906,7 @@ def join_on_conjunctions(self, pieces, additional_parts_count=0):
906906
# If it's the first piece and there are more than 1 rootnames, assume it's a first name
907907
continue
908908
next_prefix = next(iter(filter(self.is_prefix, pieces[i + 1:])))
909-
j = pieces.index(next_prefix)
909+
j = pieces.index(next_prefix, i+1)
910910
if j == i + 1:
911911
# if there are two prefixes in sequence, join to the following piece
912912
j += 1

tests.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -2071,6 +2071,10 @@ def test_multiple_prefixes(self):
20712071
self.m(hn.first, "Mike", hn)
20722072
self.m(hn.last, "van der Velt", hn)
20732073

2074+
def test_prefix_as_fist_name(self):
2075+
hh = HumanName("Van Ma Van")
2076+
self.m(hh.first, "Van Ma", hh)
2077+
self.m(hh.last, "Van", hh)
20742078

20752079
class HumanNameCapitalizationTestCase(HumanNameTestBase):
20762080
def test_capitalization_exception_for_III(self):
@@ -2343,12 +2347,12 @@ def test_initials_with_prefix_firstname(self):
23432347
def test_initials_with_prefix(self):
23442348
hn = HumanName("Alex van Johnson")
23452349
self.m(hn.initials_list(), ["A", "J"], hn)
2346-
2350+
23472351
def test_constructor_first(self):
23482352
hn = HumanName(first="TheName")
23492353
self.assertFalse(hn.unparsable)
23502354
self.m(hn.first, "TheName", hn)
2351-
2355+
23522356
def test_constructor_middle(self):
23532357
hn = HumanName(middle="TheName")
23542358
self.assertFalse(hn.unparsable)
@@ -2380,7 +2384,7 @@ def test_constructor_multiple(self):
23802384
self.m(hn.first, "TheName", hn)
23812385
self.m(hn.last, "lastname", hn)
23822386
self.m(hn.title, "mytitle", hn)
2383-
2387+
23842388

23852389
TEST_NAMES = (
23862390
"John Doe",

0 commit comments

Comments
 (0)