Skip to content

SVG export: Incorrect escaping for HTML within legend label #17753

@1tgr

Description

@1tgr

Expected behaviour

When useHTML: true, a legend label whose HTML has a < symbol inside an attribute value produces valid SVG when exported.

Actual behaviour

The < symbol is not escaped on the exported SVG. Instead, it appears as a literal character within an SVG attribute value.

Live demo with steps to reproduce

https://jsfiddle.net/y7vtpzb4/2

  1. Add the exporting module:
    <script src="https://code.highcharts.com/modules/exporting.js"></script>
  2. Write JS code:
    Highcharts.chart('container', {
        legend: {
            useHTML: true,
            labelFormatter: () => `<span title="&lt;">hover on me</span>`,
        },
    
        series: [{
            data: [[1, 1]]
        }]
    });
    
  3. Click the button at the corner of the chart and export to an SVG file
  4. Open the SVG file in an editor and observe invalid XML:

    error on line 1 at column 4222: Unescaped '<' not allowed in attributes values

Product version

Highcharts 10.1.0, 10.2.1

Affected browser(s)

Google Chrome on Windows version 105.0.5195.127
Safari on Mac OS version 15.6.1 (17613.3.9.1.16)

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions