Skip to content

Commit

Permalink
Fix a bug in CSS cloning error handler
Browse files Browse the repository at this point in the history
Firefox throws SecurityError when `cssRules` is accessed, which exposes
this bug.

Fixes #245
  • Loading branch information
spect88 committed Nov 5, 2015
1 parent 17be68f commit ef29079
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ var cloneCssStyles = function(svg, classes){
}
}
}
catch(err) {
if(rule !== 'undefined'){
catch (err) {
if (typeof(rule) !== 'undefined') {
log.warn('Invalid CSS selector "' + rule.selectorText + '"', err);
}
}
Expand Down Expand Up @@ -134,4 +134,4 @@ var cloneCssStyles = function(svg, classes){
}
};

export {cloneCssStyles};
export {cloneCssStyles};
14 changes: 14 additions & 0 deletions src/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,20 @@ describe('when cloning CSS ', function () {
document.styleSheets[styleSheetCount].title = 'mermaid-svg-internal-css';
}

it('should handle errors thrown when accessing CSS rules', function() {
var svg = document.createElement('svg');
svg.setAttribute('id', 'mermaid-01');

// Firefox throws a SecurityError when trying to access cssRules
document.styleSheets[document.styleSheets.length++] = {
get cssRules() { throw new Error('SecurityError'); }
};

expect(function() {
utils.cloneCssStyles(svg, {});
}).not.toThrow();
});

it('should handle an empty set of classes', function () {
var svg = document.createElement('svg');
svg.setAttribute('id', 'mermaid-01');
Expand Down

0 comments on commit ef29079

Please sign in to comment.