MCPcopy Create free account
hub / github.com/Lobos/react-ui / dangerousStyleValue

Function dangerousStyleValue

docs/lib/react.js:16322–16367  ·  view source on GitHub ↗

* Convert a value into the proper css writable value. The style name `name` * should be logical (no hyphens), as specified * in `CSSProperty.isUnitlessNumber`. * * @param {string} name CSS property name such as `topMargin`. * @param {*} value CSS property value such as `10px`. * @param {ReactD

(name, value, component)

Source from the content-addressed store, hash-verified

16320 * @return {string} Normalized style value with dimensions applied.
16321 */
16322function dangerousStyleValue(name, value, component) {
16323 // Note that we've removed escapeTextForBrowser() calls here since the
16324 // whole string will be escaped when the attribute is injected into
16325 // the markup. If you provide unsafe user data here they can inject
16326 // arbitrary CSS which may be problematic (I couldn't repro this):
16327 // https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet
16328 // http://www.thespanner.co.uk/2007/11/26/ultimate-xss-css-injection/
16329 // This is not an XSS hole but instead a potential CSS injection issue
16330 // which has lead to a greater discussion about how we're going to
16331 // trust URLs moving forward. See #2115901
16332
16333 var isEmpty = value == null || typeof value === 'boolean' || value === '';
16334 if (isEmpty) {
16335 return '';
16336 }
16337
16338 var isNonNumeric = isNaN(value);
16339 if (isNonNumeric || value === 0 || isUnitlessNumber.hasOwnProperty(name) && isUnitlessNumber[name]) {
16340 return '' + value; // cast to string
16341 }
16342
16343 if (typeof value === 'string') {
16344 if ("development" !== 'production') {
16345 if (component) {
16346 var owner = component._currentElement._owner;
16347 var ownerName = owner ? owner.getName() : null;
16348 if (ownerName && !styleWarnings[ownerName]) {
16349 styleWarnings[ownerName] = {};
16350 }
16351 var warned = false;
16352 if (ownerName) {
16353 var warnings = styleWarnings[ownerName];
16354 warned = warnings[name];
16355 if (!warned) {
16356 warnings[name] = true;
16357 }
16358 }
16359 if (!warned) {
16360 "development" !== 'production' ? warning(false, 'a `%s` tag (owner: `%s`) was passed a numeric string value ' + 'for CSS property `%s` (value: `%s`) which will be treated ' + 'as a unitless number in a future version of React.', component._currentElement.type, ownerName || 'unknown', name, value) : void 0;
16361 }
16362 }
16363 }
16364 value = value.trim();
16365 }
16366 return value + 'px';
16367}
16368
16369module.exports = dangerousStyleValue;
16370},{"166":166,"3":3}],117:[function(_dereq_,module,exports){

Callers 1

react.jsFile · 0.85

Calls 1

warningFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…