MCPcopy Create free account
hub / github.com/angular-ui/ui-grid / $interpolate

Function $interpolate

lib/test/angular/1.6.7/angular.js:13144–13255  ·  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

13142 * - `context`: evaluation context for all expressions embedded in the interpolated text
13143 */
13144 function $interpolate(text, mustHaveExpression, trustedContext, allOrNothing) {
13145 // Provide a quick exit and simplified result function for text with no interpolation
13146 if (!text.length || text.indexOf(startSymbol) === -1) {
13147 var constantInterp;
13148 if (!mustHaveExpression) {
13149 var unescapedText = unescapeText(text);
13150 constantInterp = valueFn(unescapedText);
13151 constantInterp.exp = text;
13152 constantInterp.expressions = [];
13153 constantInterp.$$watchDelegate = constantWatchDelegate;
13154 }
13155 return constantInterp;
13156 }
13157
13158 allOrNothing = !!allOrNothing;
13159 var startIndex,
13160 endIndex,
13161 index = 0,
13162 expressions = [],
13163 parseFns = [],
13164 textLength = text.length,
13165 exp,
13166 concat = [],
13167 expressionPositions = [];
13168
13169 while (index < textLength) {
13170 if (((startIndex = text.indexOf(startSymbol, index)) !== -1) &&
13171 ((endIndex = text.indexOf(endSymbol, startIndex + startSymbolLength)) !== -1)) {
13172 if (index !== startIndex) {
13173 concat.push(unescapeText(text.substring(index, startIndex)));
13174 }
13175 exp = text.substring(startIndex + startSymbolLength, endIndex);
13176 expressions.push(exp);
13177 parseFns.push($parse(exp, parseStringifyInterceptor));
13178 index = endIndex + endSymbolLength;
13179 expressionPositions.push(concat.length);
13180 concat.push('');
13181 } else {
13182 // we did not find an interpolation, so we have to add the remainder to the separators array
13183 if (index !== textLength) {
13184 concat.push(unescapeText(text.substring(index)));
13185 }
13186 break;
13187 }
13188 }
13189
13190 // Concatenating expressions makes it hard to reason about whether some combination of
13191 // concatenated values are unsafe to use and could easily lead to XSS. By requiring that a
13192 // single expression be used for iframe[src], object[src], etc., we ensure that the value
13193 // that's used is assigned or constructed by some JS code somewhere that is more testable or
13194 // make it obvious that you bound the value to some user controlled value. This helps reduce
13195 // the load when auditing for XSS issues.
13196 if (trustedContext && concat.length > 1) {
13197 $interpolateMinErr.throwNoconcat(text);
13198 }
13199
13200 if (!mustHaveExpression || expressions.length) {
13201 var compute = function(values) {

Callers 7

FormControllerFunction · 0.70
angular.jsFile · 0.70
NgModelControllerFunction · 0.70
angular-animate.jsFile · 0.70

Calls 6

unescapeTextFunction · 0.70
valueFnFunction · 0.70
$parseFunction · 0.70
extendFunction · 0.70
computeFunction · 0.70
isFunctionFunction · 0.70

Tested by

no test coverage detected