mirror of
https://github.com/svg/svgo.git
synced 2025-07-31 07:44:22 +03:00
Add better parser errors (#1553)
Old SVGO errors were not very helpful. Packages like cssnano (postcss-svgo) had to deal with a lot of issues which are hard to debug with old errors. ``` Error: Error in parsing SVG: Unquoted attribute value Line: 1 Column: 29 Char: 6 File: input.svg ``` New errors are more informative and may solve many struggles ``` Error: SvgoParserError: input.svg:2:29: Unquoted attribute value 1 | <svg viewBox="0 0 120 120"> > 2 | <circle fill="#ff0000" cx=60.444444" cy="60" r="50"/> | ^ 3 | </svg> 4 | ```
This commit is contained in:
@ -341,46 +341,4 @@ describe('svg2js', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('malformed svg', function () {
|
||||
var filepath = PATH.resolve(__dirname, './test.bad.svg'),
|
||||
root,
|
||||
error;
|
||||
|
||||
beforeAll(function (done) {
|
||||
FS.readFile(filepath, 'utf8', function (err, data) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
try {
|
||||
root = SVG2JS(data);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('root', function () {
|
||||
it('should have property "error"', function () {
|
||||
expect(root).toHaveProperty('error');
|
||||
});
|
||||
});
|
||||
|
||||
describe('root.error', function () {
|
||||
it('should be "Error in parsing SVG: Unexpected close tag"', function () {
|
||||
expect(root.error).toEqual(
|
||||
'Error in parsing SVG: Unexpected close tag\nLine: 10\nColumn: 15\nChar: >'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('error', function () {
|
||||
it('should not be thrown', function () {
|
||||
expect(error).not.toEqual(expect.anything());
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user