Structure change (#4220)

* Structure change

* Remove duplicate folders from previous structure

* Cleanup websocket protocol

* Updating from based off PR

* Fixup - remove wrong files during conflict and get the websocket working

* renaming tsx to ts

Co-authored-by: Jeremy Letto <jeremy.letto@datasite.com>
This commit is contained in:
Joseph Chamish 2021-01-20 18:50:18 -05:00 committed by GitHub
parent a0deb73df6
commit 1ddc9cc929
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
123 changed files with 424 additions and 228 deletions

View file

@ -0,0 +1,8 @@
function s4() {
const s4 = Math.floor((1 + Math.random()) * 0x10000);
return s4.toString(16).substring(1);
}
export function guid() {
return s4() + s4() + "-" + s4() + "-" + s4() + "-" + s4() + "-" + s4() + s4() + s4();
}

View file

@ -0,0 +1,2 @@
export * from "./guid.util";
export * from "./sanitizeHtml.util";

View file

@ -0,0 +1,51 @@
import $ from "jquery";
export function sanitizeHtml(msg) {
const $div = $("<div>").html(msg);
const whitelist = {
tags: "br,a,img,center,b,font",
attrs: ["href","color"],
href: ["http://","https://","ftp://","//"]
};
// remove all tags, attributes, and href protocols except some
enforceTagWhitelist($div, whitelist.tags);
enforceAttrWhitelist($div, whitelist.attrs);
enforceHrefWhitelist($div, whitelist.href);
return $div.html();
}
function enforceTagWhitelist($el, tags) {
$el.find("*").not(tags).each(function() {
$(this).replaceWith(this.innerHTML);
});
}
function enforceAttrWhitelist($el, attrs) {
$el.find("*").each(function() {
var attributes = this.attributes;
var i = attributes.length;
while( i-- ) {
var attr = attributes[i];
if( $.inArray(attr.name,attrs) === -1 )
this.removeAttributeNode(attr);
}
});
}
function enforceHrefWhitelist($el, hrefs) {
$el.find("[href]").each(function() {
const $_el = $(this);
const attributeValue = $_el.attr("href");
for (let protocol in hrefs) {
if (attributeValue.indexOf(hrefs[protocol]) === 0) {
$_el.attr("target", "_blank");
return;
}
}
$_el.removeAttr("href");
});
}