@braintree/sanitize-url

A url sanitizer

@braintree/sanitize-url downloads @braintree/sanitize-url version @braintree/sanitize-url license

@braintree/sanitize-urlSimilar Packages:
Npm Package Weekly Downloads Trend
3 Years
🌟 Show real-time usage chart on @braintree/sanitize-url's README.md, just copy the code below.
## Usage Trend
[![Usage Trend of @braintree/sanitize-url](https://npm-compare.com/img/npm-trend/THREE_YEARS/@braintree/sanitize-url.png)](https://npm-compare.com/@braintree/sanitize-url#timeRange=THREE_YEARS)
Cumulative GitHub Star Trend
🌟 Show GitHub stars trend chart on @braintree/sanitize-url's README.md, just copy the code below.
## GitHub Stars Trend
[![GitHub Stars Trend of @braintree/sanitize-url](https://npm-compare.com/img/github-trend/@braintree/sanitize-url.png)](https://npm-compare.com/@braintree/sanitize-url)
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
@braintree/sanitize-url2,964,36635323.8 kB1110 months agoMIT
README for @braintree/sanitize-url

sanitize-url

Installation

npm install -S @braintree/sanitize-url

Usage

var sanitizeUrl = require("@braintree/sanitize-url").sanitizeUrl;

sanitizeUrl("https://example.com"); // 'https://example.com'
sanitizeUrl("http://example.com"); // 'http://example.com'
sanitizeUrl("www.example.com"); // 'www.example.com'
sanitizeUrl("mailto:hello@example.com"); // 'mailto:hello@example.com'
sanitizeUrl(
  "https&#0000058//example.com"
); // https://example.com

sanitizeUrl("javascript:alert(document.domain)"); // 'about:blank'
sanitizeUrl("jAvasCrIPT:alert(document.domain)"); // 'about:blank'
sanitizeUrl(decodeURIComponent("JaVaScRiP%0at:alert(document.domain)")); // 'about:blank'
// HTML encoded javascript:alert('XSS')
sanitizeUrl(
  "&#0000106&#0000097&#0000118&#0000097&#0000115&#0000099&#0000114&#0000105&#0000112&#0000116&#0000058&#0000097&#0000108&#0000101&#0000114&#0000116&#0000040&#0000039&#0000088&#0000083&#0000083&#0000039&#0000041"
); // 'about:blank'

Testing

This library uses Vitest. All testing dependencies will be installed upon npm install and the test suite can be executed with npm test. Running the test suite will also run lint checks upon exiting.

npm test

To generate a coverage report, use npm run coverage.