1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149 |
- /*!
- * @esri/arcgis-html-sanitizer - v2.10.0 - Tue Mar 15 2022 16:38:25 GMT-0400 (Eastern Daylight Time)
- * Copyright (c) 2022 - Environmental Systems Research Institute, Inc.
- * Apache-2.0
- *
- * js-xss
- * Copyright (c) 2012-2017 Zongmin Lei(雷宗民) <leizongmin@gmail.com>
- * http://ucdok.com
- * MIT License, see https://github.com/leizongmin/js-xss/blob/master/LICENSE for details
- *
- * Lodash/isPlainObject
- * Copyright (c) JS Foundation and other contributors <https://js.foundation/>
- * MIT License, see https://raw.githubusercontent.com/lodash/lodash/4.17.10-npm/LICENSE for details
- */
- /**
- * lodash (Custom Build) <https://lodash.com/>
- * Build: `lodash modularize exports="npm" -o ./`
- * Copyright jQuery Foundation and other contributors <https://jquery.org/>
- * Released under MIT license <https://lodash.com/license>
- * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
- * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
- */
- /** `Object#toString` result references. */
- var objectTag = '[object Object]';
- /**
- * Checks if `value` is a host object in IE < 9.
- *
- * @private
- * @param {*} value The value to check.
- * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
- */
- function isHostObject(value) {
- // Many host objects are `Object` objects that can coerce to strings
- // despite having improperly defined `toString` methods.
- var result = false;
- if (value != null && typeof value.toString != 'function') {
- try {
- result = !!(value + '');
- } catch (e) {}
- }
- return result;
- }
- /**
- * Creates a unary function that invokes `func` with its argument transformed.
- *
- * @private
- * @param {Function} func The function to wrap.
- * @param {Function} transform The argument transform.
- * @returns {Function} Returns the new function.
- */
- function overArg(func, transform) {
- return function(arg) {
- return func(transform(arg));
- };
- }
- /** Used for built-in method references. */
- var funcProto = Function.prototype,
- objectProto = Object.prototype;
- /** Used to resolve the decompiled source of functions. */
- var funcToString = funcProto.toString;
- /** Used to check objects for own properties. */
- var hasOwnProperty = objectProto.hasOwnProperty;
- /** Used to infer the `Object` constructor. */
- var objectCtorString = funcToString.call(Object);
- /**
- * Used to resolve the
- * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
- * of values.
- */
- var objectToString = objectProto.toString;
- /** Built-in value references. */
- var getPrototype = overArg(Object.getPrototypeOf, Object);
- /**
- * Checks if `value` is object-like. A value is object-like if it's not `null`
- * and has a `typeof` result of "object".
- *
- * @static
- * @memberOf _
- * @since 4.0.0
- * @category Lang
- * @param {*} value The value to check.
- * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
- * @example
- *
- * _.isObjectLike({});
- * // => true
- *
- * _.isObjectLike([1, 2, 3]);
- * // => true
- *
- * _.isObjectLike(_.noop);
- * // => false
- *
- * _.isObjectLike(null);
- * // => false
- */
- function isObjectLike(value) {
- return !!value && typeof value == 'object';
- }
- /**
- * Checks if `value` is a plain object, that is, an object created by the
- * `Object` constructor or one with a `[[Prototype]]` of `null`.
- *
- * @static
- * @memberOf _
- * @since 0.8.0
- * @category Lang
- * @param {*} value The value to check.
- * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
- * @example
- *
- * function Foo() {
- * this.a = 1;
- * }
- *
- * _.isPlainObject(new Foo);
- * // => false
- *
- * _.isPlainObject([1, 2, 3]);
- * // => false
- *
- * _.isPlainObject({ 'x': 0, 'y': 0 });
- * // => true
- *
- * _.isPlainObject(Object.create(null));
- * // => true
- */
- function isPlainObject(value) {
- if (!isObjectLike(value) ||
- objectToString.call(value) != objectTag || isHostObject(value)) {
- return false;
- }
- var proto = getPrototype(value);
- if (proto === null) {
- return true;
- }
- var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
- return (typeof Ctor == 'function' &&
- Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString);
- }
- var lodash_isplainobject = isPlainObject;
- var lib$1 = {exports: {}};
- var _default$1 = {};
- var lib = {exports: {}};
- var _default = {};
- /**
- * cssfilter
- *
- * @author 老雷<leizongmin@gmail.com>
- */
- function getDefaultWhiteList$1 () {
- // 白名单值说明:
- // true: 允许该属性
- // Function: function (val) { } 返回true表示允许该属性,其他值均表示不允许
- // RegExp: regexp.test(val) 返回true表示允许该属性,其他值均表示不允许
- // 除上面列出的值外均表示不允许
- var whiteList = {};
- whiteList['align-content'] = false; // default: auto
- whiteList['align-items'] = false; // default: auto
- whiteList['align-self'] = false; // default: auto
- whiteList['alignment-adjust'] = false; // default: auto
- whiteList['alignment-baseline'] = false; // default: baseline
- whiteList['all'] = false; // default: depending on individual properties
- whiteList['anchor-point'] = false; // default: none
- whiteList['animation'] = false; // default: depending on individual properties
- whiteList['animation-delay'] = false; // default: 0
- whiteList['animation-direction'] = false; // default: normal
- whiteList['animation-duration'] = false; // default: 0
- whiteList['animation-fill-mode'] = false; // default: none
- whiteList['animation-iteration-count'] = false; // default: 1
- whiteList['animation-name'] = false; // default: none
- whiteList['animation-play-state'] = false; // default: running
- whiteList['animation-timing-function'] = false; // default: ease
- whiteList['azimuth'] = false; // default: center
- whiteList['backface-visibility'] = false; // default: visible
- whiteList['background'] = true; // default: depending on individual properties
- whiteList['background-attachment'] = true; // default: scroll
- whiteList['background-clip'] = true; // default: border-box
- whiteList['background-color'] = true; // default: transparent
- whiteList['background-image'] = true; // default: none
- whiteList['background-origin'] = true; // default: padding-box
- whiteList['background-position'] = true; // default: 0% 0%
- whiteList['background-repeat'] = true; // default: repeat
- whiteList['background-size'] = true; // default: auto
- whiteList['baseline-shift'] = false; // default: baseline
- whiteList['binding'] = false; // default: none
- whiteList['bleed'] = false; // default: 6pt
- whiteList['bookmark-label'] = false; // default: content()
- whiteList['bookmark-level'] = false; // default: none
- whiteList['bookmark-state'] = false; // default: open
- whiteList['border'] = true; // default: depending on individual properties
- whiteList['border-bottom'] = true; // default: depending on individual properties
- whiteList['border-bottom-color'] = true; // default: current color
- whiteList['border-bottom-left-radius'] = true; // default: 0
- whiteList['border-bottom-right-radius'] = true; // default: 0
- whiteList['border-bottom-style'] = true; // default: none
- whiteList['border-bottom-width'] = true; // default: medium
- whiteList['border-collapse'] = true; // default: separate
- whiteList['border-color'] = true; // default: depending on individual properties
- whiteList['border-image'] = true; // default: none
- whiteList['border-image-outset'] = true; // default: 0
- whiteList['border-image-repeat'] = true; // default: stretch
- whiteList['border-image-slice'] = true; // default: 100%
- whiteList['border-image-source'] = true; // default: none
- whiteList['border-image-width'] = true; // default: 1
- whiteList['border-left'] = true; // default: depending on individual properties
- whiteList['border-left-color'] = true; // default: current color
- whiteList['border-left-style'] = true; // default: none
- whiteList['border-left-width'] = true; // default: medium
- whiteList['border-radius'] = true; // default: 0
- whiteList['border-right'] = true; // default: depending on individual properties
- whiteList['border-right-color'] = true; // default: current color
- whiteList['border-right-style'] = true; // default: none
- whiteList['border-right-width'] = true; // default: medium
- whiteList['border-spacing'] = true; // default: 0
- whiteList['border-style'] = true; // default: depending on individual properties
- whiteList['border-top'] = true; // default: depending on individual properties
- whiteList['border-top-color'] = true; // default: current color
- whiteList['border-top-left-radius'] = true; // default: 0
- whiteList['border-top-right-radius'] = true; // default: 0
- whiteList['border-top-style'] = true; // default: none
- whiteList['border-top-width'] = true; // default: medium
- whiteList['border-width'] = true; // default: depending on individual properties
- whiteList['bottom'] = false; // default: auto
- whiteList['box-decoration-break'] = true; // default: slice
- whiteList['box-shadow'] = true; // default: none
- whiteList['box-sizing'] = true; // default: content-box
- whiteList['box-snap'] = true; // default: none
- whiteList['box-suppress'] = true; // default: show
- whiteList['break-after'] = true; // default: auto
- whiteList['break-before'] = true; // default: auto
- whiteList['break-inside'] = true; // default: auto
- whiteList['caption-side'] = false; // default: top
- whiteList['chains'] = false; // default: none
- whiteList['clear'] = true; // default: none
- whiteList['clip'] = false; // default: auto
- whiteList['clip-path'] = false; // default: none
- whiteList['clip-rule'] = false; // default: nonzero
- whiteList['color'] = true; // default: implementation dependent
- whiteList['color-interpolation-filters'] = true; // default: auto
- whiteList['column-count'] = false; // default: auto
- whiteList['column-fill'] = false; // default: balance
- whiteList['column-gap'] = false; // default: normal
- whiteList['column-rule'] = false; // default: depending on individual properties
- whiteList['column-rule-color'] = false; // default: current color
- whiteList['column-rule-style'] = false; // default: medium
- whiteList['column-rule-width'] = false; // default: medium
- whiteList['column-span'] = false; // default: none
- whiteList['column-width'] = false; // default: auto
- whiteList['columns'] = false; // default: depending on individual properties
- whiteList['contain'] = false; // default: none
- whiteList['content'] = false; // default: normal
- whiteList['counter-increment'] = false; // default: none
- whiteList['counter-reset'] = false; // default: none
- whiteList['counter-set'] = false; // default: none
- whiteList['crop'] = false; // default: auto
- whiteList['cue'] = false; // default: depending on individual properties
- whiteList['cue-after'] = false; // default: none
- whiteList['cue-before'] = false; // default: none
- whiteList['cursor'] = false; // default: auto
- whiteList['direction'] = false; // default: ltr
- whiteList['display'] = true; // default: depending on individual properties
- whiteList['display-inside'] = true; // default: auto
- whiteList['display-list'] = true; // default: none
- whiteList['display-outside'] = true; // default: inline-level
- whiteList['dominant-baseline'] = false; // default: auto
- whiteList['elevation'] = false; // default: level
- whiteList['empty-cells'] = false; // default: show
- whiteList['filter'] = false; // default: none
- whiteList['flex'] = false; // default: depending on individual properties
- whiteList['flex-basis'] = false; // default: auto
- whiteList['flex-direction'] = false; // default: row
- whiteList['flex-flow'] = false; // default: depending on individual properties
- whiteList['flex-grow'] = false; // default: 0
- whiteList['flex-shrink'] = false; // default: 1
- whiteList['flex-wrap'] = false; // default: nowrap
- whiteList['float'] = false; // default: none
- whiteList['float-offset'] = false; // default: 0 0
- whiteList['flood-color'] = false; // default: black
- whiteList['flood-opacity'] = false; // default: 1
- whiteList['flow-from'] = false; // default: none
- whiteList['flow-into'] = false; // default: none
- whiteList['font'] = true; // default: depending on individual properties
- whiteList['font-family'] = true; // default: implementation dependent
- whiteList['font-feature-settings'] = true; // default: normal
- whiteList['font-kerning'] = true; // default: auto
- whiteList['font-language-override'] = true; // default: normal
- whiteList['font-size'] = true; // default: medium
- whiteList['font-size-adjust'] = true; // default: none
- whiteList['font-stretch'] = true; // default: normal
- whiteList['font-style'] = true; // default: normal
- whiteList['font-synthesis'] = true; // default: weight style
- whiteList['font-variant'] = true; // default: normal
- whiteList['font-variant-alternates'] = true; // default: normal
- whiteList['font-variant-caps'] = true; // default: normal
- whiteList['font-variant-east-asian'] = true; // default: normal
- whiteList['font-variant-ligatures'] = true; // default: normal
- whiteList['font-variant-numeric'] = true; // default: normal
- whiteList['font-variant-position'] = true; // default: normal
- whiteList['font-weight'] = true; // default: normal
- whiteList['grid'] = false; // default: depending on individual properties
- whiteList['grid-area'] = false; // default: depending on individual properties
- whiteList['grid-auto-columns'] = false; // default: auto
- whiteList['grid-auto-flow'] = false; // default: none
- whiteList['grid-auto-rows'] = false; // default: auto
- whiteList['grid-column'] = false; // default: depending on individual properties
- whiteList['grid-column-end'] = false; // default: auto
- whiteList['grid-column-start'] = false; // default: auto
- whiteList['grid-row'] = false; // default: depending on individual properties
- whiteList['grid-row-end'] = false; // default: auto
- whiteList['grid-row-start'] = false; // default: auto
- whiteList['grid-template'] = false; // default: depending on individual properties
- whiteList['grid-template-areas'] = false; // default: none
- whiteList['grid-template-columns'] = false; // default: none
- whiteList['grid-template-rows'] = false; // default: none
- whiteList['hanging-punctuation'] = false; // default: none
- whiteList['height'] = true; // default: auto
- whiteList['hyphens'] = false; // default: manual
- whiteList['icon'] = false; // default: auto
- whiteList['image-orientation'] = false; // default: auto
- whiteList['image-resolution'] = false; // default: normal
- whiteList['ime-mode'] = false; // default: auto
- whiteList['initial-letters'] = false; // default: normal
- whiteList['inline-box-align'] = false; // default: last
- whiteList['justify-content'] = false; // default: auto
- whiteList['justify-items'] = false; // default: auto
- whiteList['justify-self'] = false; // default: auto
- whiteList['left'] = false; // default: auto
- whiteList['letter-spacing'] = true; // default: normal
- whiteList['lighting-color'] = true; // default: white
- whiteList['line-box-contain'] = false; // default: block inline replaced
- whiteList['line-break'] = false; // default: auto
- whiteList['line-grid'] = false; // default: match-parent
- whiteList['line-height'] = false; // default: normal
- whiteList['line-snap'] = false; // default: none
- whiteList['line-stacking'] = false; // default: depending on individual properties
- whiteList['line-stacking-ruby'] = false; // default: exclude-ruby
- whiteList['line-stacking-shift'] = false; // default: consider-shifts
- whiteList['line-stacking-strategy'] = false; // default: inline-line-height
- whiteList['list-style'] = true; // default: depending on individual properties
- whiteList['list-style-image'] = true; // default: none
- whiteList['list-style-position'] = true; // default: outside
- whiteList['list-style-type'] = true; // default: disc
- whiteList['margin'] = true; // default: depending on individual properties
- whiteList['margin-bottom'] = true; // default: 0
- whiteList['margin-left'] = true; // default: 0
- whiteList['margin-right'] = true; // default: 0
- whiteList['margin-top'] = true; // default: 0
- whiteList['marker-offset'] = false; // default: auto
- whiteList['marker-side'] = false; // default: list-item
- whiteList['marks'] = false; // default: none
- whiteList['mask'] = false; // default: border-box
- whiteList['mask-box'] = false; // default: see individual properties
- whiteList['mask-box-outset'] = false; // default: 0
- whiteList['mask-box-repeat'] = false; // default: stretch
- whiteList['mask-box-slice'] = false; // default: 0 fill
- whiteList['mask-box-source'] = false; // default: none
- whiteList['mask-box-width'] = false; // default: auto
- whiteList['mask-clip'] = false; // default: border-box
- whiteList['mask-image'] = false; // default: none
- whiteList['mask-origin'] = false; // default: border-box
- whiteList['mask-position'] = false; // default: center
- whiteList['mask-repeat'] = false; // default: no-repeat
- whiteList['mask-size'] = false; // default: border-box
- whiteList['mask-source-type'] = false; // default: auto
- whiteList['mask-type'] = false; // default: luminance
- whiteList['max-height'] = true; // default: none
- whiteList['max-lines'] = false; // default: none
- whiteList['max-width'] = true; // default: none
- whiteList['min-height'] = true; // default: 0
- whiteList['min-width'] = true; // default: 0
- whiteList['move-to'] = false; // default: normal
- whiteList['nav-down'] = false; // default: auto
- whiteList['nav-index'] = false; // default: auto
- whiteList['nav-left'] = false; // default: auto
- whiteList['nav-right'] = false; // default: auto
- whiteList['nav-up'] = false; // default: auto
- whiteList['object-fit'] = false; // default: fill
- whiteList['object-position'] = false; // default: 50% 50%
- whiteList['opacity'] = false; // default: 1
- whiteList['order'] = false; // default: 0
- whiteList['orphans'] = false; // default: 2
- whiteList['outline'] = false; // default: depending on individual properties
- whiteList['outline-color'] = false; // default: invert
- whiteList['outline-offset'] = false; // default: 0
- whiteList['outline-style'] = false; // default: none
- whiteList['outline-width'] = false; // default: medium
- whiteList['overflow'] = false; // default: depending on individual properties
- whiteList['overflow-wrap'] = false; // default: normal
- whiteList['overflow-x'] = false; // default: visible
- whiteList['overflow-y'] = false; // default: visible
- whiteList['padding'] = true; // default: depending on individual properties
- whiteList['padding-bottom'] = true; // default: 0
- whiteList['padding-left'] = true; // default: 0
- whiteList['padding-right'] = true; // default: 0
- whiteList['padding-top'] = true; // default: 0
- whiteList['page'] = false; // default: auto
- whiteList['page-break-after'] = false; // default: auto
- whiteList['page-break-before'] = false; // default: auto
- whiteList['page-break-inside'] = false; // default: auto
- whiteList['page-policy'] = false; // default: start
- whiteList['pause'] = false; // default: implementation dependent
- whiteList['pause-after'] = false; // default: implementation dependent
- whiteList['pause-before'] = false; // default: implementation dependent
- whiteList['perspective'] = false; // default: none
- whiteList['perspective-origin'] = false; // default: 50% 50%
- whiteList['pitch'] = false; // default: medium
- whiteList['pitch-range'] = false; // default: 50
- whiteList['play-during'] = false; // default: auto
- whiteList['position'] = false; // default: static
- whiteList['presentation-level'] = false; // default: 0
- whiteList['quotes'] = false; // default: text
- whiteList['region-fragment'] = false; // default: auto
- whiteList['resize'] = false; // default: none
- whiteList['rest'] = false; // default: depending on individual properties
- whiteList['rest-after'] = false; // default: none
- whiteList['rest-before'] = false; // default: none
- whiteList['richness'] = false; // default: 50
- whiteList['right'] = false; // default: auto
- whiteList['rotation'] = false; // default: 0
- whiteList['rotation-point'] = false; // default: 50% 50%
- whiteList['ruby-align'] = false; // default: auto
- whiteList['ruby-merge'] = false; // default: separate
- whiteList['ruby-position'] = false; // default: before
- whiteList['shape-image-threshold'] = false; // default: 0.0
- whiteList['shape-outside'] = false; // default: none
- whiteList['shape-margin'] = false; // default: 0
- whiteList['size'] = false; // default: auto
- whiteList['speak'] = false; // default: auto
- whiteList['speak-as'] = false; // default: normal
- whiteList['speak-header'] = false; // default: once
- whiteList['speak-numeral'] = false; // default: continuous
- whiteList['speak-punctuation'] = false; // default: none
- whiteList['speech-rate'] = false; // default: medium
- whiteList['stress'] = false; // default: 50
- whiteList['string-set'] = false; // default: none
- whiteList['tab-size'] = false; // default: 8
- whiteList['table-layout'] = false; // default: auto
- whiteList['text-align'] = true; // default: start
- whiteList['text-align-last'] = true; // default: auto
- whiteList['text-combine-upright'] = true; // default: none
- whiteList['text-decoration'] = true; // default: none
- whiteList['text-decoration-color'] = true; // default: currentColor
- whiteList['text-decoration-line'] = true; // default: none
- whiteList['text-decoration-skip'] = true; // default: objects
- whiteList['text-decoration-style'] = true; // default: solid
- whiteList['text-emphasis'] = true; // default: depending on individual properties
- whiteList['text-emphasis-color'] = true; // default: currentColor
- whiteList['text-emphasis-position'] = true; // default: over right
- whiteList['text-emphasis-style'] = true; // default: none
- whiteList['text-height'] = true; // default: auto
- whiteList['text-indent'] = true; // default: 0
- whiteList['text-justify'] = true; // default: auto
- whiteList['text-orientation'] = true; // default: mixed
- whiteList['text-overflow'] = true; // default: clip
- whiteList['text-shadow'] = true; // default: none
- whiteList['text-space-collapse'] = true; // default: collapse
- whiteList['text-transform'] = true; // default: none
- whiteList['text-underline-position'] = true; // default: auto
- whiteList['text-wrap'] = true; // default: normal
- whiteList['top'] = false; // default: auto
- whiteList['transform'] = false; // default: none
- whiteList['transform-origin'] = false; // default: 50% 50% 0
- whiteList['transform-style'] = false; // default: flat
- whiteList['transition'] = false; // default: depending on individual properties
- whiteList['transition-delay'] = false; // default: 0s
- whiteList['transition-duration'] = false; // default: 0s
- whiteList['transition-property'] = false; // default: all
- whiteList['transition-timing-function'] = false; // default: ease
- whiteList['unicode-bidi'] = false; // default: normal
- whiteList['vertical-align'] = false; // default: baseline
- whiteList['visibility'] = false; // default: visible
- whiteList['voice-balance'] = false; // default: center
- whiteList['voice-duration'] = false; // default: auto
- whiteList['voice-family'] = false; // default: implementation dependent
- whiteList['voice-pitch'] = false; // default: medium
- whiteList['voice-range'] = false; // default: medium
- whiteList['voice-rate'] = false; // default: normal
- whiteList['voice-stress'] = false; // default: normal
- whiteList['voice-volume'] = false; // default: medium
- whiteList['volume'] = false; // default: medium
- whiteList['white-space'] = false; // default: normal
- whiteList['widows'] = false; // default: 2
- whiteList['width'] = true; // default: auto
- whiteList['will-change'] = false; // default: auto
- whiteList['word-break'] = true; // default: normal
- whiteList['word-spacing'] = true; // default: normal
- whiteList['word-wrap'] = true; // default: normal
- whiteList['wrap-flow'] = false; // default: auto
- whiteList['wrap-through'] = false; // default: wrap
- whiteList['writing-mode'] = false; // default: horizontal-tb
- whiteList['z-index'] = false; // default: auto
- return whiteList;
- }
- /**
- * 匹配到白名单上的一个属性时
- *
- * @param {String} name
- * @param {String} value
- * @param {Object} options
- * @return {String}
- */
- function onAttr (name, value, options) {
- // do nothing
- }
- /**
- * 匹配到不在白名单上的一个属性时
- *
- * @param {String} name
- * @param {String} value
- * @param {Object} options
- * @return {String}
- */
- function onIgnoreAttr (name, value, options) {
- // do nothing
- }
- var REGEXP_URL_JAVASCRIPT = /javascript\s*\:/img;
- /**
- * 过滤属性值
- *
- * @param {String} name
- * @param {String} value
- * @return {String}
- */
- function safeAttrValue$1(name, value) {
- if (REGEXP_URL_JAVASCRIPT.test(value)) return '';
- return value;
- }
- _default.whiteList = getDefaultWhiteList$1();
- _default.getDefaultWhiteList = getDefaultWhiteList$1;
- _default.onAttr = onAttr;
- _default.onIgnoreAttr = onIgnoreAttr;
- _default.safeAttrValue = safeAttrValue$1;
- var util$1 = {
- indexOf: function (arr, item) {
- var i, j;
- if (Array.prototype.indexOf) {
- return arr.indexOf(item);
- }
- for (i = 0, j = arr.length; i < j; i++) {
- if (arr[i] === item) {
- return i;
- }
- }
- return -1;
- },
- forEach: function (arr, fn, scope) {
- var i, j;
- if (Array.prototype.forEach) {
- return arr.forEach(fn, scope);
- }
- for (i = 0, j = arr.length; i < j; i++) {
- fn.call(scope, arr[i], i, arr);
- }
- },
- trim: function (str) {
- if (String.prototype.trim) {
- return str.trim();
- }
- return str.replace(/(^\s*)|(\s*$)/g, '');
- },
- trimRight: function (str) {
- if (String.prototype.trimRight) {
- return str.trimRight();
- }
- return str.replace(/(\s*$)/g, '');
- }
- };
- /**
- * cssfilter
- *
- * @author 老雷<leizongmin@gmail.com>
- */
- var _$3 = util$1;
- /**
- * 解析style
- *
- * @param {String} css
- * @param {Function} onAttr 处理属性的函数
- * 参数格式: function (sourcePosition, position, name, value, source)
- * @return {String}
- */
- function parseStyle$1 (css, onAttr) {
- css = _$3.trimRight(css);
- if (css[css.length - 1] !== ';') css += ';';
- var cssLength = css.length;
- var isParenthesisOpen = false;
- var lastPos = 0;
- var i = 0;
- var retCSS = '';
- function addNewAttr () {
- // 如果没有正常的闭合圆括号,则直接忽略当前属性
- if (!isParenthesisOpen) {
- var source = _$3.trim(css.slice(lastPos, i));
- var j = source.indexOf(':');
- if (j !== -1) {
- var name = _$3.trim(source.slice(0, j));
- var value = _$3.trim(source.slice(j + 1));
- // 必须有属性名称
- if (name) {
- var ret = onAttr(lastPos, retCSS.length, name, value, source);
- if (ret) retCSS += ret + '; ';
- }
- }
- }
- lastPos = i + 1;
- }
- for (; i < cssLength; i++) {
- var c = css[i];
- if (c === '/' && css[i + 1] === '*') {
- // 备注开始
- var j = css.indexOf('*/', i + 2);
- // 如果没有正常的备注结束,则后面的部分全部跳过
- if (j === -1) break;
- // 直接将当前位置调到备注结尾,并且初始化状态
- i = j + 1;
- lastPos = i + 1;
- isParenthesisOpen = false;
- } else if (c === '(') {
- isParenthesisOpen = true;
- } else if (c === ')') {
- isParenthesisOpen = false;
- } else if (c === ';') {
- if (isParenthesisOpen) ; else {
- addNewAttr();
- }
- } else if (c === '\n') {
- addNewAttr();
- }
- }
- return _$3.trim(retCSS);
- }
- var parser$2 = parseStyle$1;
- /**
- * cssfilter
- *
- * @author 老雷<leizongmin@gmail.com>
- */
- var DEFAULT$1 = _default;
- var parseStyle = parser$2;
- /**
- * 返回值是否为空
- *
- * @param {Object} obj
- * @return {Boolean}
- */
- function isNull$1 (obj) {
- return (obj === undefined || obj === null);
- }
- /**
- * 浅拷贝对象
- *
- * @param {Object} obj
- * @return {Object}
- */
- function shallowCopyObject$1 (obj) {
- var ret = {};
- for (var i in obj) {
- ret[i] = obj[i];
- }
- return ret;
- }
- /**
- * 创建CSS过滤器
- *
- * @param {Object} options
- * - {Object} whiteList
- * - {Function} onAttr
- * - {Function} onIgnoreAttr
- * - {Function} safeAttrValue
- */
- function FilterCSS$2 (options) {
- options = shallowCopyObject$1(options || {});
- options.whiteList = options.whiteList || DEFAULT$1.whiteList;
- options.onAttr = options.onAttr || DEFAULT$1.onAttr;
- options.onIgnoreAttr = options.onIgnoreAttr || DEFAULT$1.onIgnoreAttr;
- options.safeAttrValue = options.safeAttrValue || DEFAULT$1.safeAttrValue;
- this.options = options;
- }
- FilterCSS$2.prototype.process = function (css) {
- // 兼容各种奇葩输入
- css = css || '';
- css = css.toString();
- if (!css) return '';
- var me = this;
- var options = me.options;
- var whiteList = options.whiteList;
- var onAttr = options.onAttr;
- var onIgnoreAttr = options.onIgnoreAttr;
- var safeAttrValue = options.safeAttrValue;
- var retCSS = parseStyle(css, function (sourcePosition, position, name, value, source) {
- var check = whiteList[name];
- var isWhite = false;
- if (check === true) isWhite = check;
- else if (typeof check === 'function') isWhite = check(value);
- else if (check instanceof RegExp) isWhite = check.test(value);
- if (isWhite !== true) isWhite = false;
- // 如果过滤后 value 为空则直接忽略
- value = safeAttrValue(name, value);
- if (!value) return;
- var opts = {
- position: position,
- sourcePosition: sourcePosition,
- source: source,
- isWhite: isWhite
- };
- if (isWhite) {
- var ret = onAttr(name, value, opts);
- if (isNull$1(ret)) {
- return name + ':' + value;
- } else {
- return ret;
- }
- } else {
- var ret = onIgnoreAttr(name, value, opts);
- if (!isNull$1(ret)) {
- return ret;
- }
- }
- });
- return retCSS;
- };
- var css = FilterCSS$2;
- /**
- * cssfilter
- *
- * @author 老雷<leizongmin@gmail.com>
- */
- (function (module, exports) {
- var DEFAULT = _default;
- var FilterCSS = css;
- /**
- * XSS过滤
- *
- * @param {String} css 要过滤的CSS代码
- * @param {Object} options 选项:whiteList, onAttr, onIgnoreAttr
- * @return {String}
- */
- function filterCSS (html, options) {
- var xss = new FilterCSS(options);
- return xss.process(html);
- }
- // 输出
- exports = module.exports = filterCSS;
- exports.FilterCSS = FilterCSS;
- for (var i in DEFAULT) exports[i] = DEFAULT[i];
- }(lib, lib.exports));
- var util = {
- indexOf: function (arr, item) {
- var i, j;
- if (Array.prototype.indexOf) {
- return arr.indexOf(item);
- }
- for (i = 0, j = arr.length; i < j; i++) {
- if (arr[i] === item) {
- return i;
- }
- }
- return -1;
- },
- forEach: function (arr, fn, scope) {
- var i, j;
- if (Array.prototype.forEach) {
- return arr.forEach(fn, scope);
- }
- for (i = 0, j = arr.length; i < j; i++) {
- fn.call(scope, arr[i], i, arr);
- }
- },
- trim: function (str) {
- if (String.prototype.trim) {
- return str.trim();
- }
- return str.replace(/(^\s*)|(\s*$)/g, "");
- },
- spaceIndex: function (str) {
- var reg = /\s|\n|\t/;
- var match = reg.exec(str);
- return match ? match.index : -1;
- },
- };
- /**
- * default settings
- *
- * @author Zongmin Lei<leizongmin@gmail.com>
- */
- var FilterCSS$1 = lib.exports.FilterCSS;
- var getDefaultCSSWhiteList = lib.exports.getDefaultWhiteList;
- var _$2 = util;
- function getDefaultWhiteList() {
- return {
- a: ["target", "href", "title"],
- abbr: ["title"],
- address: [],
- area: ["shape", "coords", "href", "alt"],
- article: [],
- aside: [],
- audio: [
- "autoplay",
- "controls",
- "crossorigin",
- "loop",
- "muted",
- "preload",
- "src",
- ],
- b: [],
- bdi: ["dir"],
- bdo: ["dir"],
- big: [],
- blockquote: ["cite"],
- br: [],
- caption: [],
- center: [],
- cite: [],
- code: [],
- col: ["align", "valign", "span", "width"],
- colgroup: ["align", "valign", "span", "width"],
- dd: [],
- del: ["datetime"],
- details: ["open"],
- div: [],
- dl: [],
- dt: [],
- em: [],
- figcaption: [],
- figure: [],
- font: ["color", "size", "face"],
- footer: [],
- h1: [],
- h2: [],
- h3: [],
- h4: [],
- h5: [],
- h6: [],
- header: [],
- hr: [],
- i: [],
- img: ["src", "alt", "title", "width", "height"],
- ins: ["datetime"],
- li: [],
- mark: [],
- nav: [],
- ol: [],
- p: [],
- pre: [],
- s: [],
- section: [],
- small: [],
- span: [],
- sub: [],
- summary: [],
- sup: [],
- strong: [],
- strike: [],
- table: ["width", "border", "align", "valign"],
- tbody: ["align", "valign"],
- td: ["width", "rowspan", "colspan", "align", "valign"],
- tfoot: ["align", "valign"],
- th: ["width", "rowspan", "colspan", "align", "valign"],
- thead: ["align", "valign"],
- tr: ["rowspan", "align", "valign"],
- tt: [],
- u: [],
- ul: [],
- video: [
- "autoplay",
- "controls",
- "crossorigin",
- "loop",
- "muted",
- "playsinline",
- "poster",
- "preload",
- "src",
- "height",
- "width",
- ],
- };
- }
- var defaultCSSFilter = new FilterCSS$1();
- /**
- * default onTag function
- *
- * @param {String} tag
- * @param {String} html
- * @param {Object} options
- * @return {String}
- */
- function onTag(tag, html, options) {
- // do nothing
- }
- /**
- * default onIgnoreTag function
- *
- * @param {String} tag
- * @param {String} html
- * @param {Object} options
- * @return {String}
- */
- function onIgnoreTag(tag, html, options) {
- // do nothing
- }
- /**
- * default onTagAttr function
- *
- * @param {String} tag
- * @param {String} name
- * @param {String} value
- * @return {String}
- */
- function onTagAttr(tag, name, value) {
- // do nothing
- }
- /**
- * default onIgnoreTagAttr function
- *
- * @param {String} tag
- * @param {String} name
- * @param {String} value
- * @return {String}
- */
- function onIgnoreTagAttr(tag, name, value) {
- // do nothing
- }
- /**
- * default escapeHtml function
- *
- * @param {String} html
- */
- function escapeHtml(html) {
- return html.replace(REGEXP_LT, "<").replace(REGEXP_GT, ">");
- }
- /**
- * default safeAttrValue function
- *
- * @param {String} tag
- * @param {String} name
- * @param {String} value
- * @param {Object} cssFilter
- * @return {String}
- */
- function safeAttrValue(tag, name, value, cssFilter) {
- // unescape attribute value firstly
- value = friendlyAttrValue(value);
- if (name === "href" || name === "src") {
- // filter `href` and `src` attribute
- // only allow the value that starts with `http://` | `https://` | `mailto:` | `/` | `#`
- value = _$2.trim(value);
- if (value === "#") return "#";
- if (
- !(
- value.substr(0, 7) === "http://" ||
- value.substr(0, 8) === "https://" ||
- value.substr(0, 7) === "mailto:" ||
- value.substr(0, 4) === "tel:" ||
- value.substr(0, 11) === "data:image/" ||
- value.substr(0, 6) === "ftp://" ||
- value.substr(0, 2) === "./" ||
- value.substr(0, 3) === "../" ||
- value[0] === "#" ||
- value[0] === "/"
- )
- ) {
- return "";
- }
- } else if (name === "background") {
- // filter `background` attribute (maybe no use)
- // `javascript:`
- REGEXP_DEFAULT_ON_TAG_ATTR_4.lastIndex = 0;
- if (REGEXP_DEFAULT_ON_TAG_ATTR_4.test(value)) {
- return "";
- }
- } else if (name === "style") {
- // `expression()`
- REGEXP_DEFAULT_ON_TAG_ATTR_7.lastIndex = 0;
- if (REGEXP_DEFAULT_ON_TAG_ATTR_7.test(value)) {
- return "";
- }
- // `url()`
- REGEXP_DEFAULT_ON_TAG_ATTR_8.lastIndex = 0;
- if (REGEXP_DEFAULT_ON_TAG_ATTR_8.test(value)) {
- REGEXP_DEFAULT_ON_TAG_ATTR_4.lastIndex = 0;
- if (REGEXP_DEFAULT_ON_TAG_ATTR_4.test(value)) {
- return "";
- }
- }
- if (cssFilter !== false) {
- cssFilter = cssFilter || defaultCSSFilter;
- value = cssFilter.process(value);
- }
- }
- // escape `<>"` before returns
- value = escapeAttrValue(value);
- return value;
- }
- // RegExp list
- var REGEXP_LT = /</g;
- var REGEXP_GT = />/g;
- var REGEXP_QUOTE = /"/g;
- var REGEXP_QUOTE_2 = /"/g;
- var REGEXP_ATTR_VALUE_1 = /&#([a-zA-Z0-9]*);?/gim;
- var REGEXP_ATTR_VALUE_COLON = /:?/gim;
- var REGEXP_ATTR_VALUE_NEWLINE = /&newline;?/gim;
- var REGEXP_DEFAULT_ON_TAG_ATTR_4 =
- /((j\s*a\s*v\s*a|v\s*b|l\s*i\s*v\s*e)\s*s\s*c\s*r\s*i\s*p\s*t\s*|m\s*o\s*c\s*h\s*a)\:/gi;
- var REGEXP_DEFAULT_ON_TAG_ATTR_7 =
- /e\s*x\s*p\s*r\s*e\s*s\s*s\s*i\s*o\s*n\s*\(.*/gi;
- var REGEXP_DEFAULT_ON_TAG_ATTR_8 = /u\s*r\s*l\s*\(.*/gi;
- /**
- * escape double quote
- *
- * @param {String} str
- * @return {String} str
- */
- function escapeQuote(str) {
- return str.replace(REGEXP_QUOTE, """);
- }
- /**
- * unescape double quote
- *
- * @param {String} str
- * @return {String} str
- */
- function unescapeQuote(str) {
- return str.replace(REGEXP_QUOTE_2, '"');
- }
- /**
- * escape html entities
- *
- * @param {String} str
- * @return {String}
- */
- function escapeHtmlEntities(str) {
- return str.replace(REGEXP_ATTR_VALUE_1, function replaceUnicode(str, code) {
- return code[0] === "x" || code[0] === "X"
- ? String.fromCharCode(parseInt(code.substr(1), 16))
- : String.fromCharCode(parseInt(code, 10));
- });
- }
- /**
- * escape html5 new danger entities
- *
- * @param {String} str
- * @return {String}
- */
- function escapeDangerHtml5Entities(str) {
- return str
- .replace(REGEXP_ATTR_VALUE_COLON, ":")
- .replace(REGEXP_ATTR_VALUE_NEWLINE, " ");
- }
- /**
- * clear nonprintable characters
- *
- * @param {String} str
- * @return {String}
- */
- function clearNonPrintableCharacter(str) {
- var str2 = "";
- for (var i = 0, len = str.length; i < len; i++) {
- str2 += str.charCodeAt(i) < 32 ? " " : str.charAt(i);
- }
- return _$2.trim(str2);
- }
- /**
- * get friendly attribute value
- *
- * @param {String} str
- * @return {String}
- */
- function friendlyAttrValue(str) {
- str = unescapeQuote(str);
- str = escapeHtmlEntities(str);
- str = escapeDangerHtml5Entities(str);
- str = clearNonPrintableCharacter(str);
- return str;
- }
- /**
- * unescape attribute value
- *
- * @param {String} str
- * @return {String}
- */
- function escapeAttrValue(str) {
- str = escapeQuote(str);
- str = escapeHtml(str);
- return str;
- }
- /**
- * `onIgnoreTag` function for removing all the tags that are not in whitelist
- */
- function onIgnoreTagStripAll() {
- return "";
- }
- /**
- * remove tag body
- * specify a `tags` list, if the tag is not in the `tags` list then process by the specify function (optional)
- *
- * @param {array} tags
- * @param {function} next
- */
- function StripTagBody(tags, next) {
- if (typeof next !== "function") {
- next = function () {};
- }
- var isRemoveAllTag = !Array.isArray(tags);
- function isRemoveTag(tag) {
- if (isRemoveAllTag) return true;
- return _$2.indexOf(tags, tag) !== -1;
- }
- var removeList = [];
- var posStart = false;
- return {
- onIgnoreTag: function (tag, html, options) {
- if (isRemoveTag(tag)) {
- if (options.isClosing) {
- var ret = "[/removed]";
- var end = options.position + ret.length;
- removeList.push([
- posStart !== false ? posStart : options.position,
- end,
- ]);
- posStart = false;
- return ret;
- } else {
- if (!posStart) {
- posStart = options.position;
- }
- return "[removed]";
- }
- } else {
- return next(tag, html, options);
- }
- },
- remove: function (html) {
- var rethtml = "";
- var lastPos = 0;
- _$2.forEach(removeList, function (pos) {
- rethtml += html.slice(lastPos, pos[0]);
- lastPos = pos[1];
- });
- rethtml += html.slice(lastPos);
- return rethtml;
- },
- };
- }
- /**
- * remove html comments
- *
- * @param {String} html
- * @return {String}
- */
- function stripCommentTag(html) {
- var retHtml = "";
- var lastPos = 0;
- while (lastPos < html.length) {
- var i = html.indexOf("<!--", lastPos);
- if (i === -1) {
- retHtml += html.slice(lastPos);
- break;
- }
- retHtml += html.slice(lastPos, i);
- var j = html.indexOf("-->", i);
- if (j === -1) {
- break;
- }
- lastPos = j + 3;
- }
- return retHtml;
- }
- /**
- * remove invisible characters
- *
- * @param {String} html
- * @return {String}
- */
- function stripBlankChar(html) {
- var chars = html.split("");
- chars = chars.filter(function (char) {
- var c = char.charCodeAt(0);
- if (c === 127) return false;
- if (c <= 31) {
- if (c === 10 || c === 13) return true;
- return false;
- }
- return true;
- });
- return chars.join("");
- }
- _default$1.whiteList = getDefaultWhiteList();
- _default$1.getDefaultWhiteList = getDefaultWhiteList;
- _default$1.onTag = onTag;
- _default$1.onIgnoreTag = onIgnoreTag;
- _default$1.onTagAttr = onTagAttr;
- _default$1.onIgnoreTagAttr = onIgnoreTagAttr;
- _default$1.safeAttrValue = safeAttrValue;
- _default$1.escapeHtml = escapeHtml;
- _default$1.escapeQuote = escapeQuote;
- _default$1.unescapeQuote = unescapeQuote;
- _default$1.escapeHtmlEntities = escapeHtmlEntities;
- _default$1.escapeDangerHtml5Entities = escapeDangerHtml5Entities;
- _default$1.clearNonPrintableCharacter = clearNonPrintableCharacter;
- _default$1.friendlyAttrValue = friendlyAttrValue;
- _default$1.escapeAttrValue = escapeAttrValue;
- _default$1.onIgnoreTagStripAll = onIgnoreTagStripAll;
- _default$1.StripTagBody = StripTagBody;
- _default$1.stripCommentTag = stripCommentTag;
- _default$1.stripBlankChar = stripBlankChar;
- _default$1.cssFilter = defaultCSSFilter;
- _default$1.getDefaultCSSWhiteList = getDefaultCSSWhiteList;
- var parser$1 = {};
- /**
- * Simple HTML Parser
- *
- * @author Zongmin Lei<leizongmin@gmail.com>
- */
- var _$1 = util;
- /**
- * get tag name
- *
- * @param {String} html e.g. '<a hef="#">'
- * @return {String}
- */
- function getTagName(html) {
- var i = _$1.spaceIndex(html);
- if (i === -1) {
- var tagName = html.slice(1, -1);
- } else {
- var tagName = html.slice(1, i + 1);
- }
- tagName = _$1.trim(tagName).toLowerCase();
- if (tagName.slice(0, 1) === "/") tagName = tagName.slice(1);
- if (tagName.slice(-1) === "/") tagName = tagName.slice(0, -1);
- return tagName;
- }
- /**
- * is close tag?
- *
- * @param {String} html 如:'<a hef="#">'
- * @return {Boolean}
- */
- function isClosing(html) {
- return html.slice(0, 2) === "</";
- }
- /**
- * parse input html and returns processed html
- *
- * @param {String} html
- * @param {Function} onTag e.g. function (sourcePosition, position, tag, html, isClosing)
- * @param {Function} escapeHtml
- * @return {String}
- */
- function parseTag$1(html, onTag, escapeHtml) {
- var rethtml = "";
- var lastPos = 0;
- var tagStart = false;
- var quoteStart = false;
- var currentPos = 0;
- var len = html.length;
- var currentTagName = "";
- var currentHtml = "";
- chariterator: for (currentPos = 0; currentPos < len; currentPos++) {
- var c = html.charAt(currentPos);
- if (tagStart === false) {
- if (c === "<") {
- tagStart = currentPos;
- continue;
- }
- } else {
- if (quoteStart === false) {
- if (c === "<") {
- rethtml += escapeHtml(html.slice(lastPos, currentPos));
- tagStart = currentPos;
- lastPos = currentPos;
- continue;
- }
- if (c === ">") {
- rethtml += escapeHtml(html.slice(lastPos, tagStart));
- currentHtml = html.slice(tagStart, currentPos + 1);
- currentTagName = getTagName(currentHtml);
- rethtml += onTag(
- tagStart,
- rethtml.length,
- currentTagName,
- currentHtml,
- isClosing(currentHtml)
- );
- lastPos = currentPos + 1;
- tagStart = false;
- continue;
- }
- if (c === '"' || c === "'") {
- var i = 1;
- var ic = html.charAt(currentPos - i);
- while (ic.trim() === "" || ic === "=") {
- if (ic === "=") {
- quoteStart = c;
- continue chariterator;
- }
- ic = html.charAt(currentPos - ++i);
- }
- }
- } else {
- if (c === quoteStart) {
- quoteStart = false;
- continue;
- }
- }
- }
- }
- if (lastPos < html.length) {
- rethtml += escapeHtml(html.substr(lastPos));
- }
- return rethtml;
- }
- var REGEXP_ILLEGAL_ATTR_NAME = /[^a-zA-Z0-9_:\.\-]/gim;
- /**
- * parse input attributes and returns processed attributes
- *
- * @param {String} html e.g. `href="#" target="_blank"`
- * @param {Function} onAttr e.g. `function (name, value)`
- * @return {String}
- */
- function parseAttr$1(html, onAttr) {
- var lastPos = 0;
- var retAttrs = [];
- var tmpName = false;
- var len = html.length;
- function addAttr(name, value) {
- name = _$1.trim(name);
- name = name.replace(REGEXP_ILLEGAL_ATTR_NAME, "").toLowerCase();
- if (name.length < 1) return;
- var ret = onAttr(name, value || "");
- if (ret) retAttrs.push(ret);
- }
- // 逐个分析字符
- for (var i = 0; i < len; i++) {
- var c = html.charAt(i);
- var v, j;
- if (tmpName === false && c === "=") {
- tmpName = html.slice(lastPos, i);
- lastPos = i + 1;
- continue;
- }
- if (tmpName !== false) {
- if (
- i === lastPos &&
- (c === '"' || c === "'") &&
- html.charAt(i - 1) === "="
- ) {
- j = html.indexOf(c, i + 1);
- if (j === -1) {
- break;
- } else {
- v = _$1.trim(html.slice(lastPos + 1, j));
- addAttr(tmpName, v);
- tmpName = false;
- i = j;
- lastPos = i + 1;
- continue;
- }
- }
- }
- if (/\s|\n|\t/.test(c)) {
- html = html.replace(/\s|\n|\t/g, " ");
- if (tmpName === false) {
- j = findNextEqual(html, i);
- if (j === -1) {
- v = _$1.trim(html.slice(lastPos, i));
- addAttr(v);
- tmpName = false;
- lastPos = i + 1;
- continue;
- } else {
- i = j - 1;
- continue;
- }
- } else {
- j = findBeforeEqual(html, i - 1);
- if (j === -1) {
- v = _$1.trim(html.slice(lastPos, i));
- v = stripQuoteWrap(v);
- addAttr(tmpName, v);
- tmpName = false;
- lastPos = i + 1;
- continue;
- } else {
- continue;
- }
- }
- }
- }
- if (lastPos < html.length) {
- if (tmpName === false) {
- addAttr(html.slice(lastPos));
- } else {
- addAttr(tmpName, stripQuoteWrap(_$1.trim(html.slice(lastPos))));
- }
- }
- return _$1.trim(retAttrs.join(" "));
- }
- function findNextEqual(str, i) {
- for (; i < str.length; i++) {
- var c = str[i];
- if (c === " ") continue;
- if (c === "=") return i;
- return -1;
- }
- }
- function findBeforeEqual(str, i) {
- for (; i > 0; i--) {
- var c = str[i];
- if (c === " ") continue;
- if (c === "=") return i;
- return -1;
- }
- }
- function isQuoteWrapString(text) {
- if (
- (text[0] === '"' && text[text.length - 1] === '"') ||
- (text[0] === "'" && text[text.length - 1] === "'")
- ) {
- return true;
- } else {
- return false;
- }
- }
- function stripQuoteWrap(text) {
- if (isQuoteWrapString(text)) {
- return text.substr(1, text.length - 2);
- } else {
- return text;
- }
- }
- parser$1.parseTag = parseTag$1;
- parser$1.parseAttr = parseAttr$1;
- /**
- * filter xss
- *
- * @author Zongmin Lei<leizongmin@gmail.com>
- */
- var FilterCSS = lib.exports.FilterCSS;
- var DEFAULT = _default$1;
- var parser = parser$1;
- var parseTag = parser.parseTag;
- var parseAttr = parser.parseAttr;
- var _ = util;
- /**
- * returns `true` if the input value is `undefined` or `null`
- *
- * @param {Object} obj
- * @return {Boolean}
- */
- function isNull(obj) {
- return obj === undefined || obj === null;
- }
- /**
- * get attributes for a tag
- *
- * @param {String} html
- * @return {Object}
- * - {String} html
- * - {Boolean} closing
- */
- function getAttrs(html) {
- var i = _.spaceIndex(html);
- if (i === -1) {
- return {
- html: "",
- closing: html[html.length - 2] === "/",
- };
- }
- html = _.trim(html.slice(i + 1, -1));
- var isClosing = html[html.length - 1] === "/";
- if (isClosing) html = _.trim(html.slice(0, -1));
- return {
- html: html,
- closing: isClosing,
- };
- }
- /**
- * shallow copy
- *
- * @param {Object} obj
- * @return {Object}
- */
- function shallowCopyObject(obj) {
- var ret = {};
- for (var i in obj) {
- ret[i] = obj[i];
- }
- return ret;
- }
- /**
- * FilterXSS class
- *
- * @param {Object} options
- * whiteList (or allowList), onTag, onTagAttr, onIgnoreTag,
- * onIgnoreTagAttr, safeAttrValue, escapeHtml
- * stripIgnoreTagBody, allowCommentTag, stripBlankChar
- * css{whiteList, onAttr, onIgnoreAttr} `css=false` means don't use `cssfilter`
- */
- function FilterXSS(options) {
- options = shallowCopyObject(options || {});
- if (options.stripIgnoreTag) {
- if (options.onIgnoreTag) {
- console.error(
- 'Notes: cannot use these two options "stripIgnoreTag" and "onIgnoreTag" at the same time'
- );
- }
- options.onIgnoreTag = DEFAULT.onIgnoreTagStripAll;
- }
- options.whiteList = options.whiteList || options.allowList || DEFAULT.whiteList;
- options.onTag = options.onTag || DEFAULT.onTag;
- options.onTagAttr = options.onTagAttr || DEFAULT.onTagAttr;
- options.onIgnoreTag = options.onIgnoreTag || DEFAULT.onIgnoreTag;
- options.onIgnoreTagAttr = options.onIgnoreTagAttr || DEFAULT.onIgnoreTagAttr;
- options.safeAttrValue = options.safeAttrValue || DEFAULT.safeAttrValue;
- options.escapeHtml = options.escapeHtml || DEFAULT.escapeHtml;
- this.options = options;
- if (options.css === false) {
- this.cssFilter = false;
- } else {
- options.css = options.css || {};
- this.cssFilter = new FilterCSS(options.css);
- }
- }
- /**
- * start process and returns result
- *
- * @param {String} html
- * @return {String}
- */
- FilterXSS.prototype.process = function (html) {
- // compatible with the input
- html = html || "";
- html = html.toString();
- if (!html) return "";
- var me = this;
- var options = me.options;
- var whiteList = options.whiteList;
- var onTag = options.onTag;
- var onIgnoreTag = options.onIgnoreTag;
- var onTagAttr = options.onTagAttr;
- var onIgnoreTagAttr = options.onIgnoreTagAttr;
- var safeAttrValue = options.safeAttrValue;
- var escapeHtml = options.escapeHtml;
- var cssFilter = me.cssFilter;
- // remove invisible characters
- if (options.stripBlankChar) {
- html = DEFAULT.stripBlankChar(html);
- }
- // remove html comments
- if (!options.allowCommentTag) {
- html = DEFAULT.stripCommentTag(html);
- }
- // if enable stripIgnoreTagBody
- var stripIgnoreTagBody = false;
- if (options.stripIgnoreTagBody) {
- var stripIgnoreTagBody = DEFAULT.StripTagBody(
- options.stripIgnoreTagBody,
- onIgnoreTag
- );
- onIgnoreTag = stripIgnoreTagBody.onIgnoreTag;
- }
- var retHtml = parseTag(
- html,
- function (sourcePosition, position, tag, html, isClosing) {
- var info = {
- sourcePosition: sourcePosition,
- position: position,
- isClosing: isClosing,
- isWhite: whiteList.hasOwnProperty(tag),
- };
- // call `onTag()`
- var ret = onTag(tag, html, info);
- if (!isNull(ret)) return ret;
- if (info.isWhite) {
- if (info.isClosing) {
- return "</" + tag + ">";
- }
- var attrs = getAttrs(html);
- var whiteAttrList = whiteList[tag];
- var attrsHtml = parseAttr(attrs.html, function (name, value) {
- // call `onTagAttr()`
- var isWhiteAttr = _.indexOf(whiteAttrList, name) !== -1;
- var ret = onTagAttr(tag, name, value, isWhiteAttr);
- if (!isNull(ret)) return ret;
- if (isWhiteAttr) {
- // call `safeAttrValue()`
- value = safeAttrValue(tag, name, value, cssFilter);
- if (value) {
- return name + '="' + value + '"';
- } else {
- return name;
- }
- } else {
- // call `onIgnoreTagAttr()`
- var ret = onIgnoreTagAttr(tag, name, value, isWhiteAttr);
- if (!isNull(ret)) return ret;
- return;
- }
- });
- // build new tag html
- var html = "<" + tag;
- if (attrsHtml) html += " " + attrsHtml;
- if (attrs.closing) html += " /";
- html += ">";
- return html;
- } else {
- // call `onIgnoreTag()`
- var ret = onIgnoreTag(tag, html, info);
- if (!isNull(ret)) return ret;
- return escapeHtml(html);
- }
- },
- escapeHtml
- );
- // if enable stripIgnoreTagBody
- if (stripIgnoreTagBody) {
- retHtml = stripIgnoreTagBody.remove(retHtml);
- }
- return retHtml;
- };
- var xss = FilterXSS;
- /**
- * xss
- *
- * @author Zongmin Lei<leizongmin@gmail.com>
- */
- (function (module, exports) {
- var DEFAULT = _default$1;
- var parser = parser$1;
- var FilterXSS = xss;
- /**
- * filter xss function
- *
- * @param {String} html
- * @param {Object} options { whiteList, onTag, onTagAttr, onIgnoreTag, onIgnoreTagAttr, safeAttrValue, escapeHtml }
- * @return {String}
- */
- function filterXSS(html, options) {
- var xss = new FilterXSS(options);
- return xss.process(html);
- }
- exports = module.exports = filterXSS;
- exports.filterXSS = filterXSS;
- exports.FilterXSS = FilterXSS;
- for (var i in DEFAULT) exports[i] = DEFAULT[i];
- for (var i in parser) exports[i] = parser[i];
- // using `xss` on the WebWorker, output `filterXSS` to the globals
- function isWorkerEnv() {
- return (
- typeof self !== "undefined" &&
- typeof DedicatedWorkerGlobalScope !== "undefined" &&
- self instanceof DedicatedWorkerGlobalScope
- );
- }
- if (isWorkerEnv()) {
- self.filterXSS = module.exports;
- }
- }(lib$1, lib$1.exports));
- /* Copyright (c) 2020 Environmental Systems Research Institute, Inc.
- * Apache-2.0
- *
- * js-xss
- * Copyright (c) 2012-2018 Zongmin Lei(雷宗民) <leizongmin@gmail.com>
- * http://ucdok.com
- * The MIT License, see
- * https://github.com/leizongmin/js-xss/blob/master/LICENSE for details
- *
- * Lodash/isPlainObject
- * Copyright (c) JS Foundation and other contributors <https://js.foundation/>
- * MIT License, see https://raw.githubusercontent.com/lodash/lodash/4.17.10-npm/LICENSE for details
- * */
- /**
- * The Sanitizer Class
- *
- * @export
- * @class Sanitizer
- */
- var Sanitizer = /** @class */ (function () {
- function Sanitizer(filterOptions, extendDefaults) {
- var _this = this;
- // Supported HTML Spec: https://doc.arcgis.com/en/arcgis-online/reference/supported-html.htm
- this.arcgisWhiteList = {
- a: ["href", "style", "target"],
- abbr: ["title"],
- audio: ["autoplay", "controls", "loop", "muted", "preload"],
- b: [],
- br: [],
- dd: ["style"],
- div: ["align", "style"],
- dl: ["style"],
- dt: ["style"],
- em: [],
- figcaption: ["style"],
- figure: ["style"],
- font: ["color", "face", "size", "style"],
- h1: ["style"],
- h2: ["style"],
- h3: ["style"],
- h4: ["style"],
- h5: ["style"],
- h6: ["style"],
- hr: [],
- i: [],
- img: ["alt", "border", "height", "src", "style", "width"],
- li: [],
- ol: [],
- p: ["style"],
- source: ["media", "src", "type"],
- span: ["style"],
- strong: [],
- sub: ["style"],
- sup: ["style"],
- table: ["border", "cellpadding", "cellspacing", "height", "style", "width"],
- tbody: [],
- tr: ["align", "height", "style", "valign"],
- td: [
- "align",
- "colspan",
- "height",
- "nowrap",
- "rowspan",
- "style",
- "valign",
- "width"
- ],
- th: [
- "align",
- "colspan",
- "height",
- "nowrap",
- "rowspan",
- "style",
- "valign",
- "width"
- ],
- u: [],
- ul: [],
- video: [
- "autoplay",
- "controls",
- "height",
- "loop",
- "muted",
- "poster",
- "preload",
- "width"
- ]
- };
- this.allowedProtocols = [
- "http",
- "https",
- "mailto",
- "iform",
- "tel",
- "flow",
- "lfmobile",
- "arcgis-navigator",
- "arcgis-appstudio-player",
- "arcgis-survey123",
- "arcgis-collector",
- "arcgis-workforce",
- "arcgis-explorer",
- "arcgis-trek2there",
- "arcgis-quickcapture",
- "mspbi",
- "comgooglemaps",
- "pdfefile",
- "pdfehttp",
- "pdfehttps",
- "boxapp",
- "boxemm",
- "awb",
- "awbs",
- "gropen",
- "radarscope"
- ];
- this.arcgisFilterOptions = {
- allowCommentTag: true,
- safeAttrValue: function (tag, name, value, cssFilter) {
- // Take over safe attribute filtering for `a` `href`, `img` `src`,
- // and `source` `src` attributes, otherwise pass onto the
- // default `XSS.safeAttrValue` method.
- if ((tag === "a" && name === "href") ||
- ((tag === "img" || tag === "source") && name === "src")) {
- return _this.sanitizeUrl(value);
- }
- return lib$1.exports.safeAttrValue(tag, name, value, cssFilter);
- }
- };
- var xssFilterOptions;
- if (filterOptions && !extendDefaults) {
- // Override the defaults
- xssFilterOptions = filterOptions;
- }
- else if (filterOptions && extendDefaults) {
- // Extend the defaults
- xssFilterOptions = Object.create(this.arcgisFilterOptions);
- Object.keys(filterOptions).forEach(function (key) {
- if (key === "whiteList") {
- // Extend the whitelist by concatenating arrays
- xssFilterOptions.whiteList = _this._extendObjectOfArrays([
- _this.arcgisWhiteList,
- filterOptions.whiteList || {}
- ]);
- }
- else {
- xssFilterOptions[key] = filterOptions[key];
- }
- });
- }
- else {
- // Only use the defaults
- xssFilterOptions = Object.create(this.arcgisFilterOptions);
- xssFilterOptions.whiteList = this.arcgisWhiteList;
- }
- this.xssFilterOptions = xssFilterOptions;
- // Make this readable to tests
- this._xssFilter = new lib$1.exports.FilterXSS(xssFilterOptions);
- }
- /**
- * Sanitizes value to remove invalid HTML tags.
- *
- * Note: If the value passed does not contain a valid JSON data type (String,
- * Number, JSON Object, Array, Boolean, or null), the value will be nullified.
- *
- * @param {any} value The value to sanitize.
- * @returns {any} The sanitized value.
- * @memberof Sanitizer
- */
- Sanitizer.prototype.sanitize = function (value, options) {
- if (options === void 0) { options = {}; }
- switch (typeof value) {
- case "number":
- if (isNaN(value) || !isFinite(value)) {
- return null;
- }
- return value;
- case "boolean":
- return value;
- case "string":
- return this._xssFilter.process(value);
- case "object":
- return this._iterateOverObject(value, options);
- default:
- if (options.allowUndefined && typeof value === "undefined") {
- return;
- }
- return null;
- }
- };
- /**
- * Sanitizes a URL string following the allowed protocols and sanitization rules.
- *
- * @param {string} value The URL to sanitize.
- * @param {{ isProtocolRequired: boolean }} options Configuration options for URL checking.
- * @returns {string} The sanitized URL if it's valid, or an empty string if the URL is invalid.
- */
- Sanitizer.prototype.sanitizeUrl = function (value, options) {
- var _a = (options !== null && options !== void 0 ? options : {}).isProtocolRequired, isProtocolRequired = _a === void 0 ? true : _a;
- var protocol = this._trim(value.substring(0, value.indexOf(":")));
- var isRootUrl = value === '/';
- var isUrlFragment = /^#/.test(value);
- var isValidProtocol = protocol && this.allowedProtocols.indexOf(protocol.toLowerCase()) > -1;
- if (isRootUrl || isUrlFragment || isValidProtocol) {
- return lib$1.exports.escapeAttrValue(value);
- }
- if (!protocol && !isProtocolRequired) {
- return lib$1.exports.escapeAttrValue("https://".concat(value));
- }
- return "";
- };
- /**
- * Sanitizes an HTML attribute value.
- *
- * @param {string} tag The tagname of the HTML element.
- * @param {string} attribute The attribute name of the HTML element.
- * @param {string} value The raw value to be used for the HTML attribute value.
- * @param {XSS.ICSSFilter} [cssFilter] The CSS filter to be used.
- * @returns {string} The sanitized attribute value.
- * @memberof Sanitizer
- */
- Sanitizer.prototype.sanitizeHTMLAttribute = function (tag, attribute, value, cssFilter) {
- // use the custom safeAttrValue function if provided
- if (typeof this.xssFilterOptions.safeAttrValue === 'function') {
- // @ts-ignore safeAttrValue does handle undefined cssFilter
- return this.xssFilterOptions.safeAttrValue(tag, attribute, value, cssFilter);
- }
- // otherwise use the default
- // @ts-ignore safeAttrValue does handle undefined cssFilter
- return lib$1.exports.safeAttrValue(tag, attribute, value, cssFilter);
- };
- /**
- * Checks if a value only contains valid HTML.
- *
- * @param {any} value The value to validate.
- * @returns {boolean}
- * @memberof Sanitizer
- */
- Sanitizer.prototype.validate = function (value, options) {
- if (options === void 0) { options = {}; }
- var sanitized = this.sanitize(value, options);
- return {
- isValid: value === sanitized,
- sanitized: sanitized
- };
- };
- /**
- * Extends an object of arrays by by concatenating arrays of the same object
- * keys. If the if the previous key's value is not an array, the next key's
- * value will replace the previous key. This method is used for extending the
- * whiteList in the XSS filter options.
- *
- * @private
- * @param {Array<{}>} objects An array of objects.
- * @returns {{}} The extended object.
- * @memberof Sanitizer
- */
- Sanitizer.prototype._extendObjectOfArrays = function (objects) {
- var finalObj = {};
- objects.forEach(function (obj) {
- Object.keys(obj).forEach(function (key) {
- if (Array.isArray(obj[key]) && Array.isArray(finalObj[key])) {
- finalObj[key] = finalObj[key].concat(obj[key]);
- }
- else {
- finalObj[key] = obj[key];
- }
- });
- });
- return finalObj;
- };
- /**
- * Iterate over a plain object or array to deeply sanitize each value.
- *
- * @private
- * @param {object} obj The object to iterate over.
- * @returns {(object | null)} The sanitized object.
- * @memberof Sanitizer
- */
- Sanitizer.prototype._iterateOverObject = function (obj, options) {
- var _this = this;
- if (options === void 0) { options = {}; }
- try {
- var hasChanged_1 = false;
- var changedObj = void 0;
- if (Array.isArray(obj)) {
- changedObj = obj.reduce(function (prev, value) {
- var validation = _this.validate(value, options);
- if (validation.isValid) {
- return prev.concat([value]);
- }
- else {
- hasChanged_1 = true;
- return prev.concat([validation.sanitized]);
- }
- }, []);
- }
- else if (!lodash_isplainobject(obj)) {
- if (options.allowUndefined && typeof obj === "undefined") {
- return;
- }
- return null;
- }
- else {
- var keys = Object.keys(obj);
- changedObj = keys.reduce(function (prev, key) {
- var value = obj[key];
- var validation = _this.validate(value, options);
- if (validation.isValid) {
- prev[key] = value;
- }
- else {
- hasChanged_1 = true;
- prev[key] = validation.sanitized;
- }
- return prev;
- }, {});
- }
- if (hasChanged_1) {
- return changedObj;
- }
- return obj;
- }
- catch (err) {
- return null;
- }
- };
- /**
- * Trim whitespace from the start and ends of a string.
- * @param {string} val The string to trim.
- * @returns {string} The trimmed string.
- */
- Sanitizer.prototype._trim = function (val) {
- // @ts-ignore This is used by Jest,
- // but TypeScript errors since it assumes `trim` is always available.
- return String.prototype.trim
- ? val.trim()
- : val.replace(/(^\s*)|(\s*$)/g, "");
- };
- return Sanitizer;
- }());
- export { Sanitizer, Sanitizer as default };
|