Skip to content

Commit 28667f8

Browse files
fix: fixed tests to be consistent with other sdks
1 parent 3b99d45 commit 28667f8

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

lib-es5/utils/index.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -301,17 +301,19 @@ function process_layer(layer) {
301301
}
302302

303303
if (!isEmpty(text)) {
304-
var re = /\$\([a-zA-Z]\w*\)/g;
305-
var start = 0;
306-
var textSource = smart_escape(decodeURIComponent(text), /[,\/]/g);
307-
text = "";
308-
for (var res = re.exec(textSource); res; res = re.exec(textSource)) {
309-
text += smart_escape(textSource.slice(start, res.index));
310-
text += res[0];
311-
start = res.index + res[0].length;
312-
}
313-
text += encodeURIComponent(textSource.slice(start));
314-
components.push(text);
304+
var variablesRegex = new RegExp(/(\$\([a-zA-Z]\w+\))/g);
305+
var textDividedByVariables = text.split(variablesRegex).filter(function (x) {
306+
return x;
307+
});
308+
var encodedParts = textDividedByVariables.map(function (subText) {
309+
var matches = variablesRegex[Symbol.match](subText);
310+
var isVariable = matches ? matches.length > 0 : false;
311+
if (isVariable) {
312+
return subText;
313+
}
314+
return encodeCurlyBraces(encodeURIComponent(smart_escape(subText, new RegExp(/([,\/])/g))));
315+
});
316+
components.push(encodedParts.join(''));
315317
}
316318
} else if (type === 'fetch') {
317319
var encodedUrl = base64EncodeURL(fetchUrl);
@@ -324,6 +326,10 @@ function process_layer(layer) {
324326
return components.join(':');
325327
}
326328

329+
function encodeCurlyBraces(input) {
330+
return input.replaceAll('(', '%28').replaceAll(')', '%29');
331+
}
332+
327333
/**
328334
* Parse radius options
329335
* @private

0 commit comments

Comments
 (0)