@@ -14853,6 +14853,85 @@ describe("$compile", () => {
1485314853 expect($$sanitizeUri).toHaveBeenCalledWith($rootScope.testUrl, false);
1485414854 });
1485514855
14856+ it("should use $$sanitizeUri when working with svg image href bindings", async () => {
14857+ const $$sanitizeUri = jasmine
14858+ .createSpy("$$sanitizeUri")
14859+ .and.returnValue("https://clean.example.org");
14860+ module.config(($provide) =>
14861+ $provide.value("$$sanitizeUri", $$sanitizeUri),
14862+ );
14863+ initInjector("test1");
14864+ $rootScope.testUrl = "https://bad.example.org";
14865+
14866+ const interpolatedHref = $compile(
14867+ '<svg><image href="{{ testUrl }}"></image></svg>',
14868+ )($rootScope);
14869+ await wait();
14870+ expect(interpolatedHref.querySelector("image").getAttribute("href")).toBe(
14871+ "https://clean.example.org",
14872+ );
14873+ expect($$sanitizeUri).toHaveBeenCalledWith($rootScope.testUrl, true);
14874+
14875+ $$sanitizeUri.calls.reset();
14876+
14877+ const ngHref = $compile(
14878+ '<svg><image ng-href="{{ testUrl }}" xlink:href=""></image></svg>',
14879+ )($rootScope);
14880+ await wait();
14881+ expect(ngHref.querySelector("image").getAttribute("href")).toBe(
14882+ "https://clean.example.org",
14883+ );
14884+ expect($$sanitizeUri).toHaveBeenCalledWith($rootScope.testUrl, true);
14885+
14886+ $$sanitizeUri.calls.reset();
14887+
14888+ const ngAttrHref = $compile(
14889+ '<svg><image ng-attr-href="{{ testUrl }}"></image></svg>',
14890+ )($rootScope);
14891+ await wait();
14892+ expect(ngAttrHref.querySelector("image").getAttribute("href")).toBe(
14893+ "https://clean.example.org",
14894+ );
14895+ expect($$sanitizeUri).toHaveBeenCalledWith($rootScope.testUrl, true);
14896+ });
14897+
14898+ it("should apply imgSrcSanitizationTrustedUrlList to svg image href bindings", async () => {
14899+ module.config(($compileProvider) =>
14900+ $compileProvider.imgSrcSanitizationTrustedUrlList(
14901+ /^https:\/\/angularjs\.org\//,
14902+ ),
14903+ );
14904+ initInjector("test1");
14905+
14906+ const disallowedDataUrl = "data:image/svg+xml;base64,PHN2Zy8+";
14907+
14908+ const hrefInterpolated = $compile(
14909+ '<svg><image href="{{ testUrl }}"></image></svg>',
14910+ )($rootScope);
14911+ $rootScope.testUrl = disallowedDataUrl;
14912+ await wait();
14913+ expect(hrefInterpolated.querySelector("image").getAttribute("href")).toBe(
14914+ `unsafe:${disallowedDataUrl}`,
14915+ );
14916+
14917+ const ngHrefInterpolated = $compile(
14918+ '<svg><image ng-href="{{ testUrl }}" xlink:href=""></image></svg>',
14919+ )($rootScope);
14920+ $rootScope.testUrl = disallowedDataUrl;
14921+ await wait();
14922+ expect(
14923+ ngHrefInterpolated.querySelector("image").getAttribute("href"),
14924+ ).toBe(`unsafe:${disallowedDataUrl}`);
14925+
14926+ const ngAttrHref = $compile(
14927+ '<svg><image ng-attr-href="data:image/svg+xml;base64,PHN2Zy8+"></image></svg>',
14928+ )($rootScope);
14929+ await wait();
14930+ expect(ngAttrHref.querySelector("image").getAttribute("href")).toBe(
14931+ `unsafe:${disallowedDataUrl}`,
14932+ );
14933+ });
14934+
1485614935 it("should require a RESOURCE_URL context for href by if not on an anchor or image", async () => {
1485714936 let error = [];
1485814937 module.decorator("$exceptionHandler", () => {
0 commit comments