Skip to content

Commit 60bc490

Browse files
apply fix from angular#8975
1 parent bd056ee commit 60bc490

File tree

3 files changed

+8562
-0
lines changed

3 files changed

+8562
-0
lines changed

Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM ubuntu:18.04
2+
3+
RUN apt-get update && apt-get install -y software-properties-common
4+
RUN DEBIAN_FRONTEND='noninteractive'
5+
RUN apt-get install -y libcurl4 curl apt-transport-https
6+
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
7+
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
8+
RUN apt-get update
9+
RUN apt-get -y install git libuv1 yarn nodejs openjdk-8-jdk
10+
RUN yarn global add grunt-cli
11+
WORKDIR /opt/angular

src/ng/compile.js

+33
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,39 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
772772
if ((nodeName === 'A' && (key === 'href' || key === 'xlinkHref')) ||
773773
(nodeName === 'IMG' && key === 'src')) {
774774
this[key] = value = $$sanitizeUri(value, key === 'src');
775+
} else if (nodeName === 'img' && key === 'srcset') {
776+
// sanitize img[srcset] values
777+
var result = "";
778+
779+
// first check if there are spaces because it's not the same pattern
780+
var trimmedSrcset = trim(value);
781+
// ( 999x ,| 999w ,| ,|, )
782+
var srcPattern = /(\s+\d+x\s*,|\s+\d+w\s*,|\s+,|,\s+)/;
783+
var pattern = /\s/.test(trimmedSrcset) ? srcPattern : /(,)/;
784+
785+
// split srcset into tuple of uri and descriptor except for the last item
786+
var rawUris = trimmedSrcset.split(pattern);
787+
788+
// for each tuples
789+
var nbrUrisWith2parts = Math.floor(rawUris.length / 2);
790+
for (var i=0; i<nbrUrisWith2parts; i++) {
791+
var innerIdx = i*2;
792+
// sanitize the uri
793+
result += $$sanitizeUri(trim( rawUris[innerIdx]), true);
794+
// add the descriptor
795+
result += ( " " + trim(rawUris[innerIdx+1]));
796+
}
797+
// split the last item into uri and descriptor
798+
var lastTuple = trim(rawUris[i*2]).split(/\s/);
799+
800+
// sanitize the last uri
801+
result += $$sanitizeUri(trim(lastTuple[0]), true);
802+
803+
// and add the last descriptor if any
804+
if( lastTuple.length === 2) {
805+
result += (" " + trim(lastTuple[1]));
806+
}
807+
this[key] = value = result;
775808
}
776809

777810
if (writeAttr !== false) {

0 commit comments

Comments
 (0)