(value, invokeType)
| 9294 | |
| 9295 | |
| 9296 | function sanitizeSrcset(value, invokeType) { |
| 9297 | if (!value) { |
| 9298 | return value; |
| 9299 | } |
| 9300 | if (!isString(value)) { |
| 9301 | throw $compileMinErr('srcset', 'Can\'t pass trusted values to `{0}`: "{1}"', invokeType, value.toString()); |
| 9302 | } |
| 9303 | |
| 9304 | // Such values are a bit too complex to handle automatically inside $sce. |
| 9305 | // Instead, we sanitize each of the URIs individually, which works, even dynamically. |
| 9306 | |
| 9307 | // It's not possible to work around this using `$sce.trustAsMediaUrl`. |
| 9308 | // If you want to programmatically set explicitly trusted unsafe URLs, you should use |
| 9309 | // `$sce.trustAsHtml` on the whole `img` tag and inject it into the DOM using the |
| 9310 | // `ng-bind-html` directive. |
| 9311 | |
| 9312 | var result = ''; |
| 9313 | |
| 9314 | // first check if there are spaces because it's not the same pattern |
| 9315 | var trimmedSrcset = trim(value); |
| 9316 | // ( 999x ,| 999w ,| ,|, ) |
| 9317 | var srcPattern = /(\s+\d+x\s*,|\s+\d+w\s*,|\s+,|,\s+)/; |
| 9318 | var pattern = /\s/.test(trimmedSrcset) ? srcPattern : /(,)/; |
| 9319 | |
| 9320 | // split srcset into tuple of uri and descriptor except for the last item |
| 9321 | var rawUris = trimmedSrcset.split(pattern); |
| 9322 | |
| 9323 | // for each tuples |
| 9324 | var nbrUrisWith2parts = Math.floor(rawUris.length / 2); |
| 9325 | for (var i = 0; i < nbrUrisWith2parts; i++) { |
| 9326 | var innerIdx = i * 2; |
| 9327 | // sanitize the uri |
| 9328 | result += $sce.getTrustedMediaUrl(trim(rawUris[innerIdx])); |
| 9329 | // add the descriptor |
| 9330 | result += ' ' + trim(rawUris[innerIdx + 1]); |
| 9331 | } |
| 9332 | |
| 9333 | // split the last item into uri and descriptor |
| 9334 | var lastTuple = trim(rawUris[i * 2]).split(/\s/); |
| 9335 | |
| 9336 | // sanitize the last uri |
| 9337 | result += $sce.getTrustedMediaUrl(trim(lastTuple[0])); |
| 9338 | |
| 9339 | // and add the last descriptor if any |
| 9340 | if (lastTuple.length === 2) { |
| 9341 | result += (' ' + trim(lastTuple[1])); |
| 9342 | } |
| 9343 | return result; |
| 9344 | } |
| 9345 | |
| 9346 | |
| 9347 | function Attributes(element, attributesToCopy) { |
no test coverage detected