🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

html-encoding-sniffer

Package Overview
Dependencies
Maintainers
6
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-encoding-sniffer - npm Package Compare versions

Comparing version

to
2.0.0

28

lib/html-encoding-sniffer.js

@@ -5,13 +5,9 @@ "use strict";

// https://html.spec.whatwg.org/#encoding-sniffing-algorithm
module.exports = function sniffHTMLEncoding(buffer, options) {
module.exports = (buffer, { transportLayerEncodingLabel, defaultEncoding = "windows-1252" } = {}) => {
let encoding = whatwgEncoding.getBOMEncoding(buffer); // see https://github.com/whatwg/html/issues/1910
if (options === undefined) {
options = {};
if (encoding === null && transportLayerEncodingLabel !== undefined) {
encoding = whatwgEncoding.labelToName(transportLayerEncodingLabel);
}
if (encoding === null && options.transportLayerEncodingLabel !== undefined) {
encoding = whatwgEncoding.labelToName(options.transportLayerEncodingLabel);
}
if (encoding === null) {

@@ -21,8 +17,4 @@ encoding = prescanMetaCharset(buffer);

if (encoding === null && options.defaultEncoding !== undefined) {
encoding = options.defaultEncoding;
}
if (encoding === null) {
encoding = "windows-1252";
encoding = defaultEncoding;
}

@@ -40,4 +32,4 @@

// "<"
let c1 = buffer[i + 1];
let c2 = buffer[i + 2];
const c1 = buffer[i + 1];
const c2 = buffer[i + 2];
const c3 = buffer[i + 3];

@@ -51,7 +43,6 @@ const c4 = buffer[i + 4];

c = buffer[i];
c1 = buffer[i + 1];
c2 = buffer[i + 2];
const cMinus1 = buffer[i - 1];
const cMinus2 = buffer[i - 2];
// --> (comment end)
if (c === 0x2D && c1 === 0x2D && c2 === 0x3E) {
i += 2;
if (c === 0x3E && cMinus1 === 0x2D && cMinus2 === 0x2D) {
break;

@@ -147,3 +138,2 @@ }

if (c === 0x3E) {
i++;
break;

@@ -150,0 +140,0 @@ }

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

Copyright © 2016 Domenic Denicola <d@domenic.me>
Copyright © 2016–2020 Domenic Denicola <d@domenic.me>

@@ -3,0 +3,0 @@ 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:

@@ -8,3 +8,3 @@ {

],
"version": "1.0.2",
"version": "2.0.0",
"author": "Domenic Denicola <d@domenic.me> (https://domenic.me/)",

@@ -19,11 +19,14 @@ "license": "MIT",

"test": "mocha",
"lint": "eslint lib test"
"lint": "eslint ."
},
"dependencies": {
"whatwg-encoding": "^1.0.1"
"whatwg-encoding": "^1.0.5"
},
"devDependencies": {
"eslint": "^3.8.0",
"mocha": "^3.1.2"
"eslint": "^6.8.0",
"mocha": "^7.0.0"
},
"engines": {
"node": ">=10"
}
}