Socket
Socket
Sign inDemoInstall

@braintree/sanitize-url

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@braintree/sanitize-url - npm Package Compare versions

Comparing version 6.0.4 to 7.0.0

dist/constants.d.ts

9

CHANGELOG.md
# CHANGELOG
## 7.0.0
- Move constant declarations from index file to `constants.ts` file
- Update to node v18
- Dev Dependency Updates
- Update to TypeScript 5
- Other minor dependency updates
## 6.0.4

@@ -4,0 +13,0 @@

1

dist/index.d.ts

@@ -1,2 +0,1 @@

export declare const BLANK_URL = "about:blank";
export declare function sanitizeUrl(url?: string): string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sanitizeUrl = exports.BLANK_URL = void 0;
var invalidProtocolRegex = /^([^\w]*)(javascript|data|vbscript)/im;
var htmlEntitiesRegex = /&#(\w+)(^\w|;)?/g;
var htmlCtrlEntityRegex = /&(newline|tab);/gi;
var ctrlCharactersRegex = /[\u0000-\u001F\u007F-\u009F\u2000-\u200D\uFEFF]/gim;
var urlSchemeRegex = /^.+(:|:)/gim;
var relativeFirstCharacters = [".", "/"];
exports.BLANK_URL = "about:blank";
exports.sanitizeUrl = void 0;
var constants_1 = require("./constants");
function isRelativeUrlWithoutProtocol(url) {
return relativeFirstCharacters.indexOf(url[0]) > -1;
return constants_1.relativeFirstCharacters.indexOf(url[0]) > -1;
}
// adapted from https://stackoverflow.com/a/29824550/2601552
function decodeHtmlCharacters(str) {
var removedNullByte = str.replace(ctrlCharactersRegex, "");
return removedNullByte.replace(htmlEntitiesRegex, function (match, dec) {
var removedNullByte = str.replace(constants_1.ctrlCharactersRegex, "");
return removedNullByte.replace(constants_1.htmlEntitiesRegex, function (match, dec) {
return String.fromCharCode(dec);

@@ -23,10 +17,10 @@ });

if (!url) {
return exports.BLANK_URL;
return constants_1.BLANK_URL;
}
var sanitizedUrl = decodeHtmlCharacters(url)
.replace(htmlCtrlEntityRegex, "")
.replace(ctrlCharactersRegex, "")
.replace(constants_1.htmlCtrlEntityRegex, "")
.replace(constants_1.ctrlCharactersRegex, "")
.trim();
if (!sanitizedUrl) {
return exports.BLANK_URL;
return constants_1.BLANK_URL;
}

@@ -36,3 +30,3 @@ if (isRelativeUrlWithoutProtocol(sanitizedUrl)) {

}
var urlSchemeParseResults = sanitizedUrl.match(urlSchemeRegex);
var urlSchemeParseResults = sanitizedUrl.match(constants_1.urlSchemeRegex);
if (!urlSchemeParseResults) {

@@ -42,4 +36,4 @@ return sanitizedUrl;

var urlScheme = urlSchemeParseResults[0];
if (invalidProtocolRegex.test(urlScheme)) {
return exports.BLANK_URL;
if (constants_1.invalidProtocolRegex.test(urlScheme)) {
return constants_1.BLANK_URL;
}

@@ -46,0 +40,0 @@ return sanitizedUrl;

{
"name": "@braintree/sanitize-url",
"version": "6.0.4",
"version": "7.0.0",
"description": "A url sanitizer",

@@ -30,3 +30,3 @@ "main": "dist/index.js",

"@typescript-eslint/eslint-plugin": "^5.54.1",
"@vitest/coverage-v8": "^0.33.0",
"@vitest/coverage-v8": "^0.34.2",
"chai": "^4.3.7",

@@ -36,7 +36,7 @@ "eslint": "^8.36.0",

"eslint-plugin-prettier": "^4.2.1",
"happy-dom": "^10.5.2",
"happy-dom": "^10.10.4",
"prettier": "^2.8.4",
"typescript": "^4.9.5",
"vitest": "^0.33.0"
"typescript": "^5.1.6",
"vitest": "^0.34.2"
}
}
/* eslint-disable no-script-url */
import { sanitizeUrl, BLANK_URL } from "..";
import { sanitizeUrl } from "..";
import { BLANK_URL } from "../constants";

@@ -4,0 +5,0 @@ describe("sanitizeUrl", () => {

@@ -1,11 +0,11 @@

const invalidProtocolRegex = /^([^\w]*)(javascript|data|vbscript)/im;
const htmlEntitiesRegex = /&#(\w+)(^\w|;)?/g;
const htmlCtrlEntityRegex = /&(newline|tab);/gi;
const ctrlCharactersRegex =
/[\u0000-\u001F\u007F-\u009F\u2000-\u200D\uFEFF]/gim;
const urlSchemeRegex = /^.+(:|:)/gim;
const relativeFirstCharacters = [".", "/"];
import {
BLANK_URL,
ctrlCharactersRegex,
htmlCtrlEntityRegex,
htmlEntitiesRegex,
invalidProtocolRegex,
relativeFirstCharacters,
urlSchemeRegex,
} from "./constants";
export const BLANK_URL = "about:blank";
function isRelativeUrlWithoutProtocol(url: string): boolean {

@@ -12,0 +12,0 @@ return relativeFirstCharacters.indexOf(url[0]) > -1;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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