mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-13 12:29:42 +02:00
Fix a bug in CSS cloning error handler
Firefox throws SecurityError when `cssRules` is accessed, which exposes this bug. Fixes #245
This commit is contained in:
@@ -80,8 +80,8 @@ var cloneCssStyles = function(svg, classes){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(err) {
|
catch (err) {
|
||||||
if(rule !== 'undefined'){
|
if (typeof(rule) !== 'undefined') {
|
||||||
log.warn('Invalid CSS selector "' + rule.selectorText + '"', err);
|
log.warn('Invalid CSS selector "' + rule.selectorText + '"', err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -104,6 +104,20 @@ describe('when cloning CSS ', function () {
|
|||||||
document.styleSheets[styleSheetCount].title = 'mermaid-svg-internal-css';
|
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 () {
|
it('should handle an empty set of classes', function () {
|
||||||
var svg = document.createElement('svg');
|
var svg = document.createElement('svg');
|
||||||
svg.setAttribute('id', 'mermaid-01');
|
svg.setAttribute('id', 'mermaid-01');
|
||||||
|
Reference in New Issue
Block a user