New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

safe-decode-uri-component

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

safe-decode-uri-component - npm Package Compare versions

Comparing version 1.1.3-native to 1.1.3

19

package.json
{
"name": "safe-decode-uri-component",
"version": "1.1.3-native",
"version": "1.1.3",
"description": "Safely decode URI components, leaving invalid sequences as they are",

@@ -8,6 +8,3 @@ "main": "src/index.js",

"test": "node tests/index",
"benchmark": "node benchmark",
"install": "prebuild-install || node-gyp rebuild",
"rebuild": "prebuild --compile",
"prebuild": "prebuild --all --strip --verbose"
"benchmark": "node benchmark"
},

@@ -29,16 +26,6 @@ "repository": {

"homepage": "https://github.com/jridgewell/safe-decode-uri-component#readme",
"engines": {
"node": ">=4.0.0"
},
"gypfile": true,
"devDependencies": {
"benchmark": "^2.1.4",
"microtime": "^2.1.6",
"prebuild": "^6.2.2"
},
"dependencies": {
"bindings": "^1.3.0",
"node-gyp": "^3.6.2",
"prebuild-install": "^2.3.0"
"microtime": "^2.1.6"
}
}

2

README.md
# safe-decode-uri-component
[![Build Status](https://travis-ci.org/jridgewell/safe-decode-uri-component.svg?branch=native)](https://travis-ci.org/jridgewell/safe-decode-uri-component)
[![Build Status](https://travis-ci.org/jridgewell/safe-decode-uri-component.svg?branch=master)](https://travis-ci.org/jridgewell/safe-decode-uri-component)

@@ -5,0 +5,0 @@ Decodes strings encoded by `encodeURI` and `encodeURIComponent`, without

@@ -1,1 +0,117 @@

module.exports = require('bindings')('safe_decode_uri_component.node');
"use strict";
module.exports = function decodeURIComponent(string) {
let k = string.indexOf('%');
if (k === -1) return string;
const length = string.length;
let decoded = '';
let last = 0;
let codepoint = 0;
let startOfOctets = k;
state = UTF8_ACCEPT;
while (k > -1 && k < length - 2) {
const high = hexCodeToInt(string[k + 1], 4);
const low = hexCodeToInt(string[k + 2], 0);
codepoint = decode(codepoint, high | low);
switch (state) {
case UTF8_ACCEPT:
decoded += string.substring(last, startOfOctets);
decoded += (codepoint <= 0xFFFF) ?
String.fromCharCode(codepoint) :
String.fromCharCode(
(0xD7C0 + (codepoint >> 10)),
(0xDC00 + (codepoint & 0x3FF))
);
codepoint = 0;
last = k + 3;
k = startOfOctets = string.indexOf('%', last);
break;
default:
k += 3;
if (k < length && string[k] === '%') break;
// Intentional fall-through
case UTF8_REJECT:
state = UTF8_ACCEPT;
codepoint = 0;
k = startOfOctets = string.indexOf('%', startOfOctets + 1);
break;
}
}
return decoded + string.substring(last);
};
const HEX = Object.assign(Object.create(null), {
'0': 0, '1': 1,
'2': 2, '3': 3,
'4': 4, '5': 5,
'6': 6, '7': 7,
'8': 8, '9': 9,
'a': 10, 'A': 10,
'b': 11, 'B': 11,
'c': 12, 'C': 12,
'd': 13, 'D': 13,
'e': 14, 'E': 14,
'f': 15, 'F': 15,
});
function hexCodeToInt(c, shift) {
const i = HEX[c];
return i === undefined ? 255 : i << shift;
}
/**
* The below algorithm is based on Bjoern Hoehrmann's DFA Unicode Decoder.
* Copyright (c) 2008-2009 Bjoern Hoehrmann <bjoern@hoehrmann.de>
* See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
*/
const UTF8_ACCEPT = 12;
const UTF8_REJECT = 0;
const UTF8_DATA = [
// The first part of the table maps bytes to character to a transition.
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 7, 7,
10, 9, 9, 9, 11, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
// The second part of the table maps a state to a new state when adding a
// transition.
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
12, 0, 0, 0, 0, 24, 36, 48, 60, 72, 84, 96,
0, 12, 12, 12, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0,
0, 24, 24, 24, 0, 0, 0, 0, 0, 0, 0, 0,
0, 24, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 48, 48, 48, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 48, 48, 0, 0, 0, 0, 0, 0, 0, 0,
0, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
// The third part maps the current transition to a mask that needs to apply
// to the byte.
0x7F, 0x3F, 0x3F, 0x3F, 0x00, 0x1F, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x07,
];
let state = UTF8_ACCEPT;
function decode(codepoint, byte) {
const type = UTF8_DATA[byte];
state = UTF8_DATA[256 + state + type];
return (codepoint << 6) | (byte & UTF8_DATA[364 + type]);
}

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