babel icon indicating copy to clipboard operation
babel copied to clipboard

Long path with space lead to wrong PO file.

Open ChameleonRed opened this issue 1 year ago • 2 comments

Overview Description

Steps to Reproduce

from io import BytesIO

from babel.messages import Catalog
from babel.messages.pofile import write_po, read_po

output_bytes = BytesIO()

catalog = Catalog()
catalog.add('test', locations=[('x x\\' * 40, 1)])
write_po(output_bytes, catalog, width=0)
data = output_bytes.getvalue()
print(data.decode('utf-8'))

input_bytes = BytesIO(data)
catalog = read_po(input_bytes)
print(catalog.get('test').locations)

Actual Results

Three paths.

Expected Results

One path 'x x\' * 40

Reproducibility

Run code.

Additional Information

I try to replace ' ' with '%20' - it is wrong but it works.

Option with not works as documented.

width=None # wrong type hints width=-1 # wrap occurs width= 0 # wrap occurs

Workaround is to replace ' ' or set large width.

ChameleonRed avatar May 05 '24 01:05 ChameleonRed

For context, xgettext does not wrap location lines, only messages, even when specifying --width=X. We should probably do the same

tomasr8 avatar Jul 25 '24 17:07 tomasr8

#1105 ties somewhat into this.

akx avatar Aug 08 '24 12:08 akx