Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4117901
ve.sanitize.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
ve.sanitize.js
View Options
/*!
* VisualEditor HTML sanitization utilities.
*
* @copyright See AUTHORS.txt
*/
/* global DOMPurify */
/**
* Parse some user HTML into a sanitized node list, making it safe to load on the page
*
* @param {string} html
* @param {boolean} [returnDocument] For internal use only (if true, return whole document)
* @return {NodeList|HTMLDocument} Sanitized node list (or HTML document, for internal use only)
*/
ve
.
sanitizeHtml
=
function
(
html
,
returnDocument
)
{
// TODO: Move MW-specific rules to ve-mw
const
addTags
=
[
'figure-inline'
],
addAttrs
=
[
'srcset'
,
// RDFa
'about'
,
'rel'
,
'resource'
,
'property'
,
'content'
,
'datatype'
,
'typeof'
];
const
options
=
{
ADD_TAGS
:
addTags
,
ADD_ATTR
:
addAttrs
,
ADD_URI_SAFE_ATTR
:
addAttrs
,
FORBID_TAGS
:
[
'style'
]
};
if
(
!
returnDocument
)
{
options
.
FORCE_BODY
=
true
;
options
.
RETURN_DOM_FRAGMENT
=
true
;
return
DOMPurify
.
sanitize
(
html
,
options
).
childNodes
;
}
options
.
RETURN_DOM
=
true
;
return
DOMPurify
.
sanitize
(
html
,
options
).
ownerDocument
;
};
/**
* Parse some user HTML into a sanitized HTML document, making it safe to load on the page
*
* @param {string} html
* @return {HTMLDocument}
*/
ve
.
sanitizeHtmlToDocument
=
function
(
html
)
{
return
ve
.
sanitizeHtml
(
html
,
true
);
};
/**
* Set an element attribute to a specific value if it is safe
*
* @param {HTMLElement} element Element
* @param {string} attr Attribute
* @param {string} val Value
* @param {string} [fallbackVal] Optional fallback value if val is unsafe (will also be safety-checked)
*/
ve
.
setAttributeSafe
=
function
(
element
,
attr
,
val
,
fallbackVal
)
{
if
(
DOMPurify
.
isValidAttribute
(
element
.
tagName
,
attr
,
val
)
)
{
element
.
setAttribute
(
attr
,
val
);
}
else
if
(
fallbackVal
!==
undefined
&&
DOMPurify
.
isValidAttribute
(
element
.
tagName
,
attr
,
fallbackVal
)
)
{
element
.
setAttribute
(
attr
,
fallbackVal
);
}
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Aug 19, 02:24 (2 w, 2 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
88/f6/8aac040765a47e2bc6044a7b8333
Default Alt Text
ve.sanitize.js (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment