Skip to content

Commit

Permalink
Handle case of null/empty replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
diurnalist committed Nov 3, 2014
1 parent 5d22659 commit 1d35be2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions addStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,11 @@ function addStyle(obj, options) {
}

function replaceText(source, id, replacement) {
var boundaries = ['/** >>' + id + ' **/', '/** ' + id + '<< **/'];
var boundaries = ["/** >>" + id + " **/", "/** " + id + "<< **/"];
var start = source.lastIndexOf(boundaries[0]);
var wrappedReplacement = boundaries[0] + replacement + boundaries[1];
var wrappedReplacement = replacement
? (boundaries[0] + replacement + boundaries[1])
: "";
if (source.lastIndexOf(boundaries[0]) >= 0) {
var end = source.lastIndexOf(boundaries[1]) + boundaries[1].length;
return source.slice(0, start) + wrappedReplacement + source.slice(end);
Expand All @@ -145,7 +147,7 @@ function replaceText(source, id, replacement) {
}

function applyToSingletonTag(styleElement, index, remove, obj) {
var css = remove ? '' : obj.css;
var css = remove ? "" : obj.css;

if(styleElement.styleSheet) {
styleElement.styleSheet.cssText = replaceText(styleElement.styleSheet.cssText, index, css);
Expand Down

0 comments on commit 1d35be2

Please sign in to comment.