From 51842d1b42dfc53d99532356f7ea8f3582ead261 Mon Sep 17 00:00:00 2001 From: Junaid Date: Mon, 23 Mar 2015 20:53:28 +0200 Subject: [PATCH 1/2] #500 regex was matching substring of variable name --- lib/app/js/app.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/app/js/app.js b/lib/app/js/app.js index df4bd73f..6eb0ed5c 100644 --- a/lib/app/js/app.js +++ b/lib/app/js/app.js @@ -136,7 +136,9 @@ angular.module('sgApp', [ return ''; } angular.forEach(variables, function(variable) { - str = str.replace(new RegExp('\\$' + variable.name, 'g'), variable.value); + if (str.match(new RegExp('\\$' + variable.name + ';', 'g'))) { + str = str.replace(new RegExp('\\$' + variable.name, 'g'), variable.value); + } }); return str; }; From 74fa4f4446857d4d22bfefddfe53a0c682f3d3ad Mon Sep 17 00:00:00 2001 From: Junaid Date: Tue, 24 Mar 2015 12:27:46 +0200 Subject: [PATCH 2/2] test added --- test/angular/unit/app.test.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/angular/unit/app.test.js b/test/angular/unit/app.test.js index e5b339e1..8560ae77 100644 --- a/test/angular/unit/app.test.js +++ b/test/angular/unit/app.test.js @@ -58,6 +58,26 @@ describe('sgApp module', function() { expect(setVariables(input, variables)).to.eql(result); }); + it('should set variables correctly if the first vairbale name is seconds substring', function() { + var input = 'background: $bgColor; color: $bgColor;', + variables = [ + {name: 'bgColor', value: '#FF0000'}, + {name: 'bgColor-light', value: '#00FF00'} + ], + result = 'background: #FF0000; color: #FF0000;'; + expect(setVariables(input, variables)).to.eql(result); + }); + + it('should set variables correctly if the second vairbale name has first vairbale name as substring', function() { + var input = 'background: $bgColor-light; color: $bgColor-light;', + variables = [ + {name: 'bgColor', value: '#FF0000'}, + {name: 'bgColor-light', value: '#00FF00'} + ], + result = 'background: #00FF00; color: #00FF00;'; + expect(setVariables(input, variables)).to.eql(result); + }); + it('should be case sensitive', function() { var input = 'background: $test;', variables = [