Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit cdb1644

Browse files
Merge pull request #8 from thgaskell/allow-multiple-substitutions
Allow multiple values to be substituted
2 parents e75c3bc + 95f24b0 commit cdb1644

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lib/sepia/src/util.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ function substituteWithOpaqueKeys(text) {
129129
var substitutions = globalOptions.substitutions;
130130
for (var i=0; i<substitutions.length; i++) {
131131
var subst = substitutions[i];
132-
text = text.replace(subst.actualValueFn(), subst.opaqueKey);
132+
text = text.split(subst.actualValueFn()).join(subst.opaqueKey);
133133
}
134134
return text;
135135
}
@@ -138,7 +138,7 @@ function substituteWithRealValues(text) {
138138
var substitutions = globalOptions.substitutions;
139139
for (var i=0; i<substitutions.length; i++) {
140140
var subst = substitutions[i];
141-
text = text.replace(subst.opaqueKey, subst.actualValueFn());
141+
text = text.split(subst.opaqueKey).join(subst.actualValueFn());
142142
}
143143
return text;
144144
}

test/util.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,21 @@ describe('utils.js', function() {
5656
var text = substituteWithOpaqueKeys('A:<OPAQUE1>:B:<OPAQUE2>:C:realvalue1:D:realvalue2');
5757
text.should.equal('A:<OPAQUE1>:B:<OPAQUE2>:C:<OPAQUE1>:D:<OPAQUE2>');
5858
});
59+
60+
it('should substitute multiple real values with opaque keys', function () {
61+
var valfn1 = function() {return 'realvalue1'; };
62+
addSubstitution('<OPAQUE1>', valfn1);
63+
64+
var text = substituteWithOpaqueKeys('A:<OPAQUE1>:B:<OPAQUE1>:C:realvalue1:D:realvalue1');
65+
text.should.equal('A:<OPAQUE1>:B:<OPAQUE1>:C:<OPAQUE1>:D:<OPAQUE1>');
66+
});
5967
});
6068

6169
describe('#substituteWithRealValues', function() {
6270
const substituteWithRealValues= sepiaUtil.substituteWithRealValues;
6371
const addSubstitution = sepiaUtil.addSubstitution;
6472

65-
it('should substitute opaque keys with opaque keys', function () {
73+
it('should substitute opaque keys with real values', function () {
6674
var valfn1 = function() {return 'realvalue1'; };
6775
var valfn2 = function() {return 'realvalue2'; };
6876
addSubstitution('<OPAQUE1>', valfn1);
@@ -71,6 +79,14 @@ describe('utils.js', function() {
7179
var text = substituteWithRealValues('A:<OPAQUE1>:B:<OPAQUE2>:C:realvalue1:D:realvalue2');
7280
text.should.equal('A:realvalue1:B:realvalue2:C:realvalue1:D:realvalue2');
7381
});
82+
83+
it('should substitute multiple instances of opaque keys with real values', function () {
84+
var valfn1 = function() {return 'realvalue1'; };
85+
addSubstitution('<OPAQUE1>', valfn1);
86+
87+
var text = substituteWithRealValues('A:<OPAQUE1>:B:<OPAQUE1>:C:realvalue1:D:realvalue1');
88+
text.should.equal('A:realvalue1:B:realvalue1:C:realvalue1:D:realvalue1');
89+
});
7490
});
7591

7692
describe('#addFilter', function() {

0 commit comments

Comments
 (0)