Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bleach

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bleach - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

test/analyze.js

43

lib/bleach.js

@@ -9,3 +9,3 @@ /*

matcher: /<\/?([a-zA-Z0-9]+)*([^\/]*?)>/igm,
matcher: /<\/?([a-zA-Z0-9]+)*([^\/]*?)\/?>/igm,

@@ -18,2 +18,5 @@ whitelist: [

analyze: function(html) {
if (!html) throw Error('You must pass in HTML as an argument.');
if (typeof html != 'string') throw Error('HTML must be a string.');
var matches = [],

@@ -23,3 +26,3 @@ match;

// extract all tags
while ((match = this.matcher.exec(html)) != null) {
while ((match = bleach.matcher.exec(html)) != null) {
var attrr = match[2].split(' '),

@@ -36,3 +39,3 @@ attrs = [];

};
attrs.push(attr);
if (attr.name) attrs.push(attr);
});

@@ -53,6 +56,8 @@

sanitize: function(html, options) {
options = options || {};
var mode = options.mode || 'white',
list = options.list || this.whitelist;
list = options.list || bleach.whitelist;
var matches = this.analyze(html);
var matches = bleach.analyze(html);

@@ -74,2 +79,30 @@ matches.forEach(function(tag){

return html;
},
youtube: function(html) {
if (!html) throw Error('You must pass in HTML as an argument.');
if (typeof html != 'string') throw Error('HTML must be a string.');
var match,
matches = [],
regex = /<object(.*)src="(http:\/\/www.youtube.com)?\/(v\/([-|~_0-9A-Za-z]+)|watch\?v\=([-|~_0-9A-Za-z]+)&?.*?).*<\/object>/gi;
while (match = regex.exec(html)) {
matches.push(match);
} delete match;
matches.forEach(function(match){
var full = match[0],
id = match[4];
var rep = '<iframe type="text/html" '
+ 'frameborder="0" '
+ 'scrolling="no" '
+ 'allowfullscreen '
+ 'src="http://youtube.com/embed/' + id + '"></iframe>';
html = html.replace(full, rep);
});
return html;
}

@@ -76,0 +109,0 @@

2

package.json

@@ -5,3 +5,3 @@ {

"description": "A minimalistic HTML sanitizer",
"version": "0.1.0",
"version": "0.1.1",
"homepage": "https://github.com/ecto/bleach/issues",

@@ -8,0 +8,0 @@ "repository": {

@@ -11,2 +11,6 @@ # bleach

## test
vows --spec test/*
## example

@@ -80,1 +84,21 @@

````
### bleach.youtube(html)
Convert valid YouTube flash embeds into HTML5-compliant iframe embeds.
````javascript
var html = bleach.youtube(html);
````
## license
(The MIT License)
Copyright (c) 2011 Cam Pedersen <cam@onswipe.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc