Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion babel/messages/pofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ def _process_comment(self, line) -> None:
try:
self.locations.append((a, int(b)))
except ValueError:
continue
# The colon is part of the filename and there is
# no line number, e.g. `C:/project/main.py`
self.locations.append((location, None))
else: # No line number specified
self.locations.append((location, None))
return
Expand Down
23 changes: 23 additions & 0 deletions tests/messages/test_pofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,29 @@ def test_enclosed_filenames_in_location_comment():
assert True is catalog.is_identical(catalog2)


def test_read_po_location_with_colon_in_filename():
buf = StringIO('''#: C:/project/main.py lib:utils.py other.py:12 C:/project/views.py:7
msgid "foo"
msgstr ""
''')
catalog = pofile.read_po(buf)
assert catalog["foo"].locations == [
("C:/project/main.py", None),
("lib:utils.py", None),
("other.py", 12),
("C:/project/views.py", 7),
]


def test_location_with_colon_in_filename_roundtrip():
catalog = Catalog()
catalog.add("foo", locations=[("C:/project/main.py", 3)], string="")
buf = BytesIO()
pofile.write_po(buf, catalog, omit_header=True, include_lineno=False)
buf.seek(0)
assert pofile.read_po(buf)["foo"].locations == [("C:/project/main.py", None)]


@pytest.mark.parametrize('include_lineno', [False, True])
@pytest.mark.parametrize(
('locations', 'with_lines', 'without_lines'),
Expand Down
4 changes: 3 additions & 1 deletion tests/messages/test_pofile_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ def test_silent_location_fallback():
msgstr ""''')
catalog = pofile.read_po(buf)
assert catalog['missing line number'].locations == [('broken_file.py', None)]
assert catalog['broken line number'].locations == []
assert catalog['broken line number'].locations == [
('broken_file.py:broken_line_number', None),
]


def test_include_lineno():
Expand Down