Skip to content

Commit

Permalink
add the Sanitizer-API
Browse files Browse the repository at this point in the history
  • Loading branch information
nuxodin committed Aug 8, 2022
1 parent a8e6386 commit e9e9001
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Initial **3Kb** to polyfill a lot of Stuff!

Add this script on the top of your page:
```html
<script src="https://cdn.jsdelivr.net/gh/nuxodin/lazyfill@1.7.4/mod.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/nuxodin/lazyfill@1.7.5/mod.min.js"></script>
```
**done!**

Expand Down Expand Up @@ -71,6 +71,7 @@ Add this script on the top of your page:
<li>children
<li>toggleAttribute
<li>scrollIntoViewIfNeeded
<li>setHTML
</ul>
<li>
Array
Expand Down Expand Up @@ -158,6 +159,8 @@ Add this script on the top of your page:
<ul>
<li>flags
</ul>
<li>
Sanitizer
<li>
String
<ul>
Expand Down
8 changes: 6 additions & 2 deletions mod.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
!function(window, document){ 'use strict';
// other libaries should check properties like so: if (prop in obj) { ... }; so the getter will not fire

var root = 'cdn.jsdelivr.net/gh/nuxodin/lazyfill@1.7.4/';
var root = 'cdn.jsdelivr.net/gh/nuxodin/lazyfill@1.7.5/';
var ending = '.min.js';

//var root = 'localhost/github/lazyfill/'; var ending = '.js';
Expand Down Expand Up @@ -53,7 +53,11 @@ var urls = {
'URLPattern':[window],
},
'unpkg.com/web-streams-polyfill@3.2.1/dist/polyfill.min.js':{
'ReadableStream':[window],
'ReadableStream':[window],
},
'raw.githubusercontent.com/mozilla/sanitizer-polyfill/main/dist/sanitizer-polyfill.min.js':{ // todo
'Sanitizer':[window],
'setHTML':[Element.prototype],
},
};

Expand Down
8 changes: 6 additions & 2 deletions test.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
console.log(S12.difference(S23))
*/

var inputValue = `<p>hi! <svg/onload="alert(1)" />well <em>please</em> <a href="javascript:alert(2)" title="pretty-please">click me!</a>`;
var contextEl = document.createElement('div');
contextEl.setHTML(inputValue, { sanitizer: new Sanitizer() });
console.log(contextEl.innerHTML)


</script>

Expand Down Expand Up @@ -95,5 +100,4 @@ <h2>focusgroup</h2>
<input type="checkbox">
</div>


<button onclick="navigator.share({title:'title',text:'text',url:location.href})">share</button>
<button onclick="navigator.share({title:'title',text:'text',url:location.href})">share</button>

0 comments on commit e9e9001

Please sign in to comment.