MCPcopy Create free account
hub / github.com/microsoft/SandDance / dangerousStyleValue

Function dangerousStyleValue

docs/external/js/react-dom.development.js:4532–4553  ·  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`. * @r

(name, value, isCustomProperty)

Source from the content-addressed store, hash-verified

4530 */
4531
4532 function dangerousStyleValue(name, value, isCustomProperty) {
4533 // Note that we've removed escapeTextForBrowser() calls here since the
4534 // whole string will be escaped when the attribute is injected into
4535 // the markup. If you provide unsafe user data here they can inject
4536 // arbitrary CSS which may be problematic (I couldn't repro this):
4537 // https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet
4538 // http://www.thespanner.co.uk/2007/11/26/ultimate-xss-css-injection/
4539 // This is not an XSS hole but instead a potential CSS injection issue
4540 // which has lead to a greater discussion about how we're going to
4541 // trust URLs moving forward. See #2115901
4542 var isEmpty = value == null || typeof value === 'boolean' || value === '';
4543
4544 if (isEmpty) {
4545 return '';
4546 }
4547
4548 if (!isCustomProperty && typeof value === 'number' && value !== 0 && !(isUnitlessNumber.hasOwnProperty(name) && isUnitlessNumber[name])) {
4549 return value + 'px'; // Presumes implicit 'px' suffix for unitless numbers
4550 }
4551
4552 return ('' + value).trim();
4553 }
4554
4555 var uppercasePattern = /([A-Z])/g;
4556 var msPattern = /^ms-/;

Callers 3

setValueForStylesFunction · 0.85
unhideInstanceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected