MCPcopy Create free account
hub / github.com/OpenReservation/OpenReservation / $interpolate

Function $interpolate

OpenReservation/wwwroot/Scripts/angular.js:12053–12166  ·  view source on GitHub ↗

* @ngdoc service * @name $interpolate * @kind function * * @requires $parse * @requires $sce * * @description * * Compiles a string with markup int

(text, mustHaveExpression, trustedContext, allOrNothing)

Source from the content-addressed store, hash-verified

12051 * - `context`: evaluation context for all expressions embedded in the interpolated text
12052 */
12053 function $interpolate(text, mustHaveExpression, trustedContext, allOrNothing) {
12054 // Provide a quick exit and simplified result function for text with no interpolation
12055 if (!text.length || text.indexOf(startSymbol) === -1) {
12056 var constantInterp;
12057 if (!mustHaveExpression) {
12058 var unescapedText = unescapeText(text);
12059 constantInterp = valueFn(unescapedText);
12060 constantInterp.exp = text;
12061 constantInterp.expressions = [];
12062 constantInterp.$$watchDelegate = constantWatchDelegate;
12063 }
12064 return constantInterp;
12065 }
12066
12067 allOrNothing = !!allOrNothing;
12068 var startIndex,
12069 endIndex,
12070 index = 0,
12071 expressions = [],
12072 parseFns = [],
12073 textLength = text.length,
12074 exp,
12075 concat = [],
12076 expressionPositions = [];
12077
12078 while (index < textLength) {
12079 if (((startIndex = text.indexOf(startSymbol, index)) != -1) &&
12080 ((endIndex = text.indexOf(endSymbol, startIndex + startSymbolLength)) != -1)) {
12081 if (index !== startIndex) {
12082 concat.push(unescapeText(text.substring(index, startIndex)));
12083 }
12084 exp = text.substring(startIndex + startSymbolLength, endIndex);
12085 expressions.push(exp);
12086 parseFns.push($parse(exp, parseStringifyInterceptor));
12087 index = endIndex + endSymbolLength;
12088 expressionPositions.push(concat.length);
12089 concat.push('');
12090 } else {
12091 // we did not find an interpolation, so we have to add the remainder to the separators array
12092 if (index !== textLength) {
12093 concat.push(unescapeText(text.substring(index)));
12094 }
12095 break;
12096 }
12097 }
12098
12099 // Concatenating expressions makes it hard to reason about whether some combination of
12100 // concatenated values are unsafe to use and could easily lead to XSS. By requiring that a
12101 // single expression be used for iframe[src], object[src], etc., we ensure that the value
12102 // that's used is assigned or constructed by some JS code somewhere that is more testable or
12103 // make it obvious that you bound the value to some user controlled value. This helps reduce
12104 // the load when auditing for XSS issues.
12105 if (trustedContext && concat.length > 1) {
12106 $interpolateMinErr.throwNoconcat(text);
12107 }
12108
12109 if (!mustHaveExpression || expressions.length) {
12110 var compute = function (values) {

Callers 5

FormControllerFunction · 0.85
angular.jsFile · 0.85

Calls 6

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

Tested by

no test coverage detected