Skip to content

Commit

Permalink
plugins/convertPathData: -1.816-9.278.682-13.604 parsing error (fix s…
Browse files Browse the repository at this point in the history
  • Loading branch information
deepsweet committed Dec 21, 2012
1 parent 0b6c2fc commit ea7173b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
16 changes: 13 additions & 3 deletions lib/svgo/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ exports.intersectArrays = function(a, b) {
exports.cleanupOutData = function(data, params) {

var str = '',
delimiter;
delimiter,
prev;

data.forEach(function(item, i) {

Expand All @@ -66,11 +67,20 @@ exports.cleanupOutData = function(data, params) {
delimiter = '';
}

// no extra space in front of negative number
if (params.negativeExtraSpace && item < 0) {
// no extra space in front of negative number or
// in front of a floating number if a previous number is floating too
if (
params.negativeExtraSpace &&
(item < 0 ||
(item > 0 && item < 1 && prev % 1 !== 0)
)
) {
delimiter = '';
}

// save prev item value
prev = item;

// remove floating-point numbers leading zeros
// 0.5 → .5
// -0.5 → -.5
Expand Down
2 changes: 1 addition & 1 deletion plugins/convertPathData.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var cleanupOutData = require('../lib/svgo/tools').cleanupOutData,
regPathInstructions = /([MmLlHhVvCcSsQqTtAaZz])\s*/,
regPathData = /[\-+]?\d*\.?\d+(\.\d+)?([eE][\-+]?\d+)?/g,
regPathData = /[\-+]?\d*\.?\d+([eE][\-+]?\d+)?/g,
pathElems = ['path', 'glyph', 'missing-glyph'],
hasMarkerMid;

Expand Down
2 changes: 2 additions & 0 deletions test/plugins/convertPathData.01.orig.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions test/plugins/convertPathData.01.should.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/plugins/convertPathData.05.should.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ea7173b

Please sign in to comment.