Skip to content

toPNG() crashes with Cannot read properties of null (reading 'toLowerCase') for multilingual content #4

@GameOver94

Description

@GameOver94

toPNG() throws a TypeError when the multilingual setting i.e. the common Latin/English is chosen. This is reproducible on the Designer demo — open the browser console and click the PNG download button with the default content.

Reproduce

await Receipt.from('Hello World', '-c 48 -l en -p escpos').toPNG();
// TypeError: Cannot read properties of null (reading 'toLowerCase')

toSVG() is unaffected.

Root Cause

Inside Base64PNG.from(), the PNG renderer reads a lang attribute from the generated SVG's <g> element:

const lang = group.getAttribute('lang').toLowerCase() || 'en';

The SVG renderer only writes that attribute for CJK/Thai scripts. For Latin content the attribute is never set, so getAttribute('lang') returns null and .toLowerCase() throws.

Fix

- const lang = group.getAttribute('lang').toLowerCase() || 'en';
+ const lang = (group.getAttribute('lang') ?? 'en').toLowerCase() || 'en';

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions