Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node - Escape unsupported characters like '<' or '>' #1922

Open
curvedriver opened this issue Apr 27, 2021 · 0 comments
Open

node - Escape unsupported characters like '<' or '>' #1922

curvedriver opened this issue Apr 27, 2021 · 0 comments

Comments

@curvedriver
Copy link

curvedriver commented Apr 27, 2021

Description/Steps to reproduce

It seems that src/node/xml.js is no longer necessary since jsdom 16 because the references issues are solved:

Removing the /src/node/xml.js workaround would also solve other encoding issues like the following:

If data attribute of a item contains < or >, then exportSVG({asString: true}) doesn't encodes these characters as &lt; or &gt; which causes issues if such a XML will be opened in chrome.

This page contains the following errors:
error on line 3 at column 57: Unescaped '<' not allowed in attributes values
Below is a rendering of the page up to the first error.

test-case

Serialize linearGradient with jsdom 16

            const path = new paper.Path('M0,0 L100,0 100,100 0,100 Z');

            const gradient = new paper.Gradient();
            gradient.stops = [
                new paper.GradientStop(new paper.Color('yellow')),
                new paper.GradientStop(new paper.Color('red')),
                new paper.GradientStop(new paper.Color('blue'))];

            path.fillColor = new paper.Color(gradient, new paper.Point(0, 0), new paper.Point(0, 100));

            paper.project.activeLayer.addChildren([path]);

            console.log('xml.js Serialize', paper.project.exportSVG({ asString: true }));
            const svgNode = paper.project.exportSVG() as SVGElement;
            
            const window = new jsdom.JSDOM('<body></body>').window;

            console.log('jsdom Serialize', new window.XMLSerializer().serializeToString(svgNode));

Serialize path.data which includes < and ´>`

            const path = new paper.Path('M0,0 L10,0 10,10 0,10 Z');
            path.fillColor = new paper.Color('blue');
            path.data = 'Is << unescaped?';

            paper.project.activeLayer.addChildren([path]);
           
            // Chrome shows the following error: 
            // error on line 1 at column 482: Unescaped '<' not allowed in attributes values
            console.log('xml.js Serialize', paper.project.exportSVG({ asString: true }));

            const svgNode = paper.project.exportSVG() as SVGElement;
            const window = new jsdom.JSDOM('<body></body>').window;

            console.log('jsdom Serialize', new window.XMLSerializer().serializeToString(svgNode));

Expected result

Unsupported characters like < and > should be encoded at the attributes if paper.project.exportSVG({ asString: true}) will be called in case of node.

Additional information

Windows 10 Pro 10586.962, Node 14.16.1, jsdom 16.5.3

@curvedriver curvedriver changed the title node - Encoding of unsupported character like '<' or '>' node - Encoding of unsupported characters like '<' or '>' Apr 27, 2021
@curvedriver curvedriver changed the title node - Encoding of unsupported characters like '<' or '>' node - Escape unsupported characters like '<' or '>' May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants