Skip to content

Commit

Permalink
Improvements on parsing error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
GreLI committed Feb 28, 2016
1 parent 81e1ebe commit 0b23ff6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions lib/svgo/svg2js.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ module.exports = function(data, callback) {
root = new JSAPI({ elem: '#document' }),
current = root,
stack = [root],
textContext = null;
textContext = null,
parsingError = false;

function pushToContent(content) {

Expand Down Expand Up @@ -143,7 +144,9 @@ module.exports = function(data, callback) {
sax.onerror = function(e) {

e.message = 'Error in parsing SVG: ' + e.message;
throw e;
if (e.message.indexOf('Unexpected end') < 0) {
throw e;
}

};

Expand All @@ -161,8 +164,9 @@ module.exports = function(data, callback) {
sax.write(data);
} catch (e) {
callback({ error: e.message });
parsingError = true;
}
sax.close();
if (!parsingError) sax.close();

function trim(elem) {
if (!elem.content) return elem;
Expand Down
6 changes: 3 additions & 3 deletions test/svg2js/_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,10 @@ describe('svg2js', function() {

});

describe('thrown error', function() {
describe('error', function() {

it('should be an instance of Error', function() {
return error.should.be.an.instanceOf(Error);
it('should not be thrown', function() {
return SHOULD.not.exist(error);
});

});
Expand Down

0 comments on commit 0b23ff6

Please sign in to comment.