Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix failing size() calls & exclude dataURIs from xlink:href detection #2

Merged
merged 2 commits into from

2 participants

@jkphl
Collaborator

Hi Michael,

I encountered two problems with SVG-Cleaner, both somehow related to each other:

  1. When a cheerio find() call fails for some reason (see 2.), it returns an empty array [], which doesn't have a size() method and thus results in an error (the process exits). As the size() method does nothing else than returning the length property (which is a native Array property as well as you know), I simply changed it to this. Not really nice, I know, but effective. I'd leave it up to you how you'd like to fix this issue though ...

  2. I happened to encounter an SVG file containing a data URI as the value of an xlink:href attribute (don't really know if this valid at all, but this is what the SVG was like). Your findReferencedElements() method would accept this as a valid ID reference (which it isn't of course), leading to an error (being the reason for 1.). This pull request includes a patch that prevents those data URIs from being registered as ID references.

Btw. do you intend to work on SVG-Cleaner any longer? Port the missing parts of Scour? Scour itself might be improved in the future, as there's a new maintainer (@oberstet) now ...

Cheers,
Joschi

@rockitbaby rockitbaby merged commit 8a11910 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 3 additions and 3 deletions.
  1. +3 −3 lib/svg-cleaner.js
View
6 lib/svg-cleaner.js
@@ -217,7 +217,7 @@ function findReferencedElements() {
// if xlink:href is set, then grab the id
var href = $node.attr('xlink:href');
- if(href) {
+ if(href && (href.indexOf('data:') !== 0)) {
addReferencingElement(ids, href, REFERENCE_TYPE.XLINK, node);
}
@@ -266,7 +266,7 @@ function shortenIDs(startNumber) {
// > (Cyn: I've seen documents with #id references but no element with that ID!)
var idList = _(_(referencedIDs).keys()).filter(function(id) {
- return ($identifiedElements.find('#' + id).size() > 0);
+ return ($identifiedElements.find('#' + id).length > 0);
});
idList = _(idList).sortBy(function(id) {
return referencedIDs[id].length;
@@ -283,7 +283,7 @@ function shortenIDs(startNumber) {
}
// scour:
// > Then, skip ahead if the new ID is already in identifiedElement
- while($identifiedElements.find('#' + shortendID).size() > 0) {
+ while($identifiedElements.find('#' + shortendID).length > 0) {
shortendID = intToID(startNumber++);
}
// scour:
Something went wrong with that request. Please try again.