MCPcopy Create free account
hub / github.com/cafebazaar/blacksmith / $interpolate

Function $interpolate

web/static/bower_components/angular/angular.js:11000–11098  ·  view source on GitHub ↗

* @ngdoc service * @name $interpolate * @kind function * * @requires $parse * @requires $sce * * @description * * Compiles a string with markup into an interpolation function. This service is used by the * HTML ng.$compile $compile service fo

(text, mustHaveExpression, trustedContext, allOrNothing)

Source from the content-addressed store, hash-verified

10998 * - `context`: evaluation context for all expressions embedded in the interpolated text
10999 */
11000 function $interpolate(text, mustHaveExpression, trustedContext, allOrNothing) {
11001 allOrNothing = !!allOrNothing;
11002 var startIndex,
11003 endIndex,
11004 index = 0,
11005 expressions = [],
11006 parseFns = [],
11007 textLength = text.length,
11008 exp,
11009 concat = [],
11010 expressionPositions = [];
11011
11012 while (index < textLength) {
11013 if (((startIndex = text.indexOf(startSymbol, index)) != -1) &&
11014 ((endIndex = text.indexOf(endSymbol, startIndex + startSymbolLength)) != -1)) {
11015 if (index !== startIndex) {
11016 concat.push(unescapeText(text.substring(index, startIndex)));
11017 }
11018 exp = text.substring(startIndex + startSymbolLength, endIndex);
11019 expressions.push(exp);
11020 parseFns.push($parse(exp, parseStringifyInterceptor));
11021 index = endIndex + endSymbolLength;
11022 expressionPositions.push(concat.length);
11023 concat.push('');
11024 } else {
11025 // we did not find an interpolation, so we have to add the remainder to the separators array
11026 if (index !== textLength) {
11027 concat.push(unescapeText(text.substring(index)));
11028 }
11029 break;
11030 }
11031 }
11032
11033 // Concatenating expressions makes it hard to reason about whether some combination of
11034 // concatenated values are unsafe to use and could easily lead to XSS. By requiring that a
11035 // single expression be used for iframe[src], object[src], etc., we ensure that the value
11036 // that's used is assigned or constructed by some JS code somewhere that is more testable or
11037 // make it obvious that you bound the value to some user controlled value. This helps reduce
11038 // the load when auditing for XSS issues.
11039 if (trustedContext && concat.length > 1) {
11040 $interpolateMinErr.throwNoconcat(text);
11041 }
11042
11043 if (!mustHaveExpression || expressions.length) {
11044 var compute = function(values) {
11045 for (var i = 0, ii = expressions.length; i < ii; i++) {
11046 if (allOrNothing && isUndefined(values[i])) return;
11047 concat[expressionPositions[i]] = values[i];
11048 }
11049 return concat.join('');
11050 };
11051
11052 var getValue = function(value) {
11053 return trustedContext ?
11054 $sce.getTrusted(trustedContext, value) :
11055 $sce.valueOf(value);
11056 };
11057

Callers 5

FormControllerFunction · 0.85
angular.jsFile · 0.85

Calls 4

unescapeTextFunction · 0.85
extendFunction · 0.85
computeFunction · 0.85
isFunctionFunction · 0.85

Tested by

no test coverage detected