bwipp / postscriptbarcode

Barcode Writer in Pure PostScript
https://bwipp.terryburton.co.uk
MIT License
463 stars 65 forks source link

`databarexpandedstackedcomposite` doesn't escape characters correctly with `parse` #256

Closed tailsu closed 10 months ago

tailsu commented 10 months ago

I generate a databarexpandedstackedcomposite with the parse option with the following content:

(01)12345678901231|(21)abcd^040X^04153442(93)INTERNAL

The generated barcode is incorrect, as it decodes to (in machine-readable format):

"0112345678901231|21abcd\x1D" "040X\x1D" "04153442\x1D" "93INTERNAL"

The escaped parentheses are apparently not correctly encoded. It should instead decode to:

"0112345678901231|21abcd(X)53442\x1D""93INTERNAL"

If I change the barcode type to databaromnicomposite, then the parentheses are correctly encoded in the barcode and the whole barcode decodes to the expected string.

terryburton commented 10 months ago

For composite symbols, multiple helper encoders are called that are passed the same instance of the options dictionary, which they modify (for example by clearing parse) before calling the ultimate encoder. However, these changes unintentionally bubble back up to the caller and therefore erroneously affect subsequent encoder calls.

I've fixed obvious issues by avoiding superfluous modifications to the options dict. I may have missed some instances in which case the generic (but less efficient) fix is of the form presented in 4e130138bddab39193290416841b477e50c9dde8.

Please test and if it looks good I'll cut a new release.

tailsu commented 10 months ago

Tested, works! Thanks for the quick fix 👍