Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
Remove package visibility restriction from goog.html.sanitizer.CssSan…
Browse files Browse the repository at this point in the history
…itizer.sanitizeInlineStyle and make it return a SafeStyle.

RELNOTES[NEW]: Make goog.html.sanitizer.CssSanitizer.sanitizeInlineStyle public.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=126817772
  • Loading branch information
daneshii authored and shicks committed Jul 7, 2016
1 parent e4beff3 commit 005bc11
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions closure/goog/deps.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions closure/goog/html/sanitizer/csssanitizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
goog.provide('goog.html.sanitizer.CssSanitizer');

goog.require('goog.array');
goog.require('goog.html.SafeStyle');
goog.require('goog.html.uncheckedconversions');
goog.require('goog.object');
goog.require('goog.string');

Expand Down Expand Up @@ -207,13 +209,12 @@ goog.html.sanitizer.CssSanitizer.sanitizeProperty_ = function(
* @param {?CSSStyleDeclaration} cssStyle A CSS style object.
* @param {function(string, string)=} opt_uriRewriter A URI rewriter that
* returns an unwrapped goog.html.SafeUrl.
* @return {?string} A sanitized inline cssText.
* @package
* @return {!goog.html.SafeStyle} A sanitized inline cssText.
*/
goog.html.sanitizer.CssSanitizer.sanitizeInlineStyle = function(
cssStyle, opt_uriRewriter) {
if (!cssStyle) {
return null;
return goog.html.SafeStyle.EMPTY;
}

var cleanCssStyle = document.createElement('div').style;
Expand All @@ -233,7 +234,10 @@ goog.html.sanitizer.CssSanitizer.sanitizeInlineStyle = function(
cleanCssStyle, propName, sanitizedValue);
}
}
return cleanCssStyle.cssText || null;
return goog.html.uncheckedconversions
.safeStyleFromStringKnownToSatisfyTypeContract(
goog.string.Const.from('Output of CSS sanitizer'),
cleanCssStyle.cssText || '');
};


Expand Down
6 changes: 4 additions & 2 deletions closure/goog/html/sanitizer/csssanitizer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
goog.setTestOnly();

goog.require('goog.array');
goog.require('goog.html.SafeStyle');
goog.require('goog.html.SafeUrl');
goog.require('goog.html.sanitizer.CssSanitizer');
goog.require('goog.string');
Expand Down Expand Up @@ -89,8 +90,9 @@ function assertCSSTextEquals(expectedCssText, actualCssText) {
*/
function getSanitizedInlineStyle(sourceCss, opt_urlRewrite) {
try {
return goog.html.sanitizer.CssSanitizer.sanitizeInlineStyle(
getStyleFromCssText(sourceCss), opt_urlRewrite) ||
return goog.html.SafeStyle.unwrap(
goog.html.sanitizer.CssSanitizer.sanitizeInlineStyle(
getStyleFromCssText(sourceCss), opt_urlRewrite)) ||
'';
} catch (err) {
// IE8 doesn't like setting invalid properties. It throws an "Invalid
Expand Down
6 changes: 4 additions & 2 deletions closure/goog/html/sanitizer/htmlsanitizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ goog.require('goog.asserts');
goog.require('goog.dom');
goog.require('goog.dom.NodeType');
goog.require('goog.functions');
goog.require('goog.html.SafeStyle');
goog.require('goog.html.SafeUrl');
goog.require('goog.html.sanitizer.AttributeWhitelist');
goog.require('goog.html.sanitizer.CssSanitizer');
Expand Down Expand Up @@ -527,8 +528,9 @@ goog.html.sanitizer.HtmlSanitizer.sanitizeCssBlock_ = function(
policyHints.cssProperty = prop;
return policySanitizeUrl(uri, policyHints);
});
return goog.html.sanitizer.CssSanitizer.sanitizeInlineStyle(
policyContext.cssStyle, naiveUriRewriter);
return goog.html.SafeStyle.unwrap(
goog.html.sanitizer.CssSanitizer.sanitizeInlineStyle(
policyContext.cssStyle, naiveUriRewriter));
};


Expand Down

0 comments on commit 005bc11

Please sign in to comment.