Izmjenjena struktura, dodan backand

This commit is contained in:
GotPPay
2017-10-16 11:19:46 +02:00
parent 1ec88afacb
commit 048e32c4aa
37153 changed files with 2975854 additions and 1 deletions

19
web/node_modules/html-encoding-sniffer/LICENSE.txt generated vendored Normal file
View File

@@ -0,0 +1,19 @@
Copyright © 2016 Domenic Denicola <d@domenic.me>
This work is free. You can redistribute it and/or modify it under the
terms of the Do What The Fuck You Want To Public License, Version 2,
as published by Sam Hocevar. See below for more details.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.

38
web/node_modules/html-encoding-sniffer/README.md generated vendored Normal file
View File

@@ -0,0 +1,38 @@
# Determine the Encoding of a HTML Byte Stream
This package implements the HTML Standard's [encoding sniffing algorithm](https://html.spec.whatwg.org/multipage/syntax.html#encoding-sniffing-algorithm) in all its glory. The most interesting part of this is how it pre-scans the first 1024 bytes in order to search for certain `<meta charset>`-related patterns.
```js
const htmlEncodingSniffer = require("html-encoding-sniffer");
const fs = require("fs");
const htmlBuffer = fs.readFileSync("./html-page.html");
const sniffedEncoding = htmlEncodingSniffer(htmlBuffer);
```
The returned value will be a canonical [encoding name](https://encoding.spec.whatwg.org/#names-and-labels) (not a label). You might then combine this with the [whatwg-encoding](https://github.com/jsdom/whatwg-encoding) package to decode the result:
```js
const whatwgEncoding = require("whatwg-encoding");
const htmlString = whatwgEncoding.decode(htmlBuffer, sniffedEncoding);
```
## Options
You can pass two potential options to `htmlEncodingSniffer`:
```js
const sniffedEncoding = htmlEncodingSniffer(htmlBuffer, {
transportLayerEncodingLabel,
defaultEncoding
});
```
These represent two possible inputs into the [encoding sniffing algorithm](https://html.spec.whatwg.org/multipage/syntax.html#encoding-sniffing-algorithm):
- `transportLayerEncodingLabel` is an encoding label that is obtained from the "transport layer" (probably a HTTP `Content-Type` header), which overrides everything but a BOM.
- `defaultEncoding` is the ultimate fallback encoding used if no valid encoding is supplied by the transport layer, and no encoding is sniffed from the bytes. It defaults to `"windows-1252"`, as recommended by the algorithm's table of suggested defaults for "All other locales" (including the `en` locale).
## Credits
This package was originally based on the excellent work of [@nicolashenry](https://github.com/nicolashenry), [in jsdom](https://github.com/tmpvar/jsdom/blob/16fd85618f2705d181232f6552125872a37164bc/lib/jsdom/living/helpers/encoding.js). It has since been pulled out into this separate package.

View File

@@ -0,0 +1,302 @@
"use strict";
const whatwgEncoding = require("whatwg-encoding");
// https://html.spec.whatwg.org/#encoding-sniffing-algorithm
module.exports = function sniffHTMLEncoding(buffer, options) {
let encoding = whatwgEncoding.getBOMEncoding(buffer); // see https://github.com/whatwg/html/issues/1910
if (options === undefined) {
options = {};
}
if (encoding === null && options.transportLayerEncodingLabel !== undefined) {
encoding = whatwgEncoding.labelToName(options.transportLayerEncodingLabel);
}
if (encoding === null) {
encoding = prescanMetaCharset(buffer);
}
if (encoding === null && options.defaultEncoding !== undefined) {
encoding = options.defaultEncoding;
}
if (encoding === null) {
encoding = "windows-1252";
}
return encoding;
};
// https://html.spec.whatwg.org/multipage/syntax.html#prescan-a-byte-stream-to-determine-its-encoding
function prescanMetaCharset(buffer) {
const l = Math.min(buffer.length, 1024);
for (let i = 0; i < l; i++) {
let c = buffer[i];
if (c === 0x3C) {
// "<"
let c1 = buffer[i + 1];
let c2 = buffer[i + 2];
const c3 = buffer[i + 3];
const c4 = buffer[i + 4];
const c5 = buffer[i + 5];
// !-- (comment start)
if (c1 === 0x21 && c2 === 0x2D && c3 === 0x2D) {
i += 4;
for (; i < l; i++) {
c = buffer[i];
c1 = buffer[i + 1];
c2 = buffer[i + 2];
// --> (comment end)
if (c === 0x2D && c1 === 0x2D && c2 === 0x3E) {
i += 2;
break;
}
}
} else if ((c1 === 0x4D || c1 === 0x6D) &&
(c2 === 0x45 || c2 === 0x65) &&
(c3 === 0x54 || c3 === 0x74) &&
(c4 === 0x41 || c4 === 0x61) &&
(isSpaceCharacter(c5) || c5 === 0x2F)) {
// "meta" + space or /
i += 6;
let gotPragma = false;
let needPragma = null;
let charset = null;
let attrRes;
do {
attrRes = getAttribute(buffer, i, l);
if (attrRes.attr) {
if (attrRes.attr.name === "http-equiv") {
gotPragma = attrRes.attr.value === "content-type";
} else if (attrRes.attr.name === "content" && !charset) {
charset = extractCharacterEncodingFromMeta(attrRes.attr.value);
if (charset !== null) {
needPragma = true;
}
} else if (attrRes.attr.name === "charset") {
charset = whatwgEncoding.labelToName(attrRes.attr.value);
needPragma = false;
}
}
i = attrRes.i;
} while (attrRes.attr);
if (needPragma === null) {
continue;
}
if (needPragma === true && gotPragma === false) {
continue;
}
if (charset === null) {
continue;
}
if (charset === "UTF-16LE" || charset === "UTF-16BE") {
charset = "UTF-8";
}
if (charset === "x-user-defined") {
charset = "windows-1252";
}
return charset;
} else if ((c1 >= 0x41 && c1 <= 0x5A) || (c1 >= 0x61 && c1 <= 0x7A)) {
// a-z or A-Z
for (i += 2; i < l; i++) {
c = buffer[i];
// space or >
if (isSpaceCharacter(c) || c === 0x3E) {
break;
}
}
let attrRes;
do {
attrRes = getAttribute(buffer, i, l);
i = attrRes.i;
} while (attrRes.attr);
} else if (c1 === 0x21 || c1 === 0x2F || c1 === 0x3F) {
// ! or / or ?
for (i += 2; i < l; i++) {
c = buffer[i];
// >
if (c === 0x3E) {
break;
}
}
}
}
}
return null;
}
// https://html.spec.whatwg.org/multipage/syntax.html#concept-get-attributes-when-sniffing
function getAttribute(buffer, i, l) {
for (; i < l; i++) {
let c = buffer[i];
// space or /
if (isSpaceCharacter(c) || c === 0x2F) {
continue;
}
// ">"
if (c === 0x3E) {
i++;
break;
}
let name = "";
let value = "";
nameLoop:for (; i < l; i++) {
c = buffer[i];
// "="
if (c === 0x3D && name !== "") {
i++;
break;
}
// space
if (isSpaceCharacter(c)) {
for (i++; i < l; i++) {
c = buffer[i];
// space
if (isSpaceCharacter(c)) {
continue;
}
// not "="
if (c !== 0x3D) {
return { attr: { name, value }, i };
}
i++;
break nameLoop;
}
break;
}
// / or >
if (c === 0x2F || c === 0x3E) {
return { attr: { name, value }, i };
}
// A-Z
if (c >= 0x41 && c <= 0x5A) {
name += String.fromCharCode(c + 0x20); // lowercase
} else {
name += String.fromCharCode(c);
}
}
c = buffer[i];
// space
if (isSpaceCharacter(c)) {
for (i++; i < l; i++) {
c = buffer[i];
// space
if (isSpaceCharacter(c)) {
continue;
} else {
break;
}
}
}
// " or '
if (c === 0x22 || c === 0x27) {
const quote = c;
for (i++; i < l; i++) {
c = buffer[i];
if (c === quote) {
i++;
return { attr: { name, value }, i };
}
// A-Z
if (c >= 0x41 && c <= 0x5A) {
value += String.fromCharCode(c + 0x20); // lowercase
} else {
value += String.fromCharCode(c);
}
}
}
// >
if (c === 0x3E) {
return { attr: { name, value }, i };
}
// A-Z
if (c >= 0x41 && c <= 0x5A) {
value += String.fromCharCode(c + 0x20); // lowercase
} else {
value += String.fromCharCode(c);
}
for (i++; i < l; i++) {
c = buffer[i];
// space or >
if (isSpaceCharacter(c) || c === 0x3E) {
return { attr: { name, value }, i };
}
// A-Z
if (c >= 0x41 && c <= 0x5A) {
value += String.fromCharCode(c + 0x20); // lowercase
} else {
value += String.fromCharCode(c);
}
}
}
return { i };
}
function extractCharacterEncodingFromMeta(string) {
let position = 0;
while (true) {
let subPosition = string.substring(position).search(/charset/i);
if (subPosition === -1) {
return null;
}
subPosition += "charset".length;
while (isSpaceCharacter(string[subPosition].charCodeAt(0))) {
++subPosition;
}
if (string[subPosition] !== "=") {
position = subPosition - 1;
continue;
}
++subPosition;
while (isSpaceCharacter(string[subPosition].charCodeAt(0))) {
++subPosition;
}
position = subPosition;
break;
}
if (string[position] === "\"" || string[position] === "'") {
const nextIndex = string.indexOf(string[position], position + 1);
if (nextIndex !== -1) {
return whatwgEncoding.labelToName(string.substring(position + 1, nextIndex));
}
// It is an unmatched quotation mark
return null;
}
if (string.length === position + 1) {
return null;
}
let end = string.substring(position + 1).search(/\x09|\x0A|\x0C|\x0D|\x20|;/);
if (end === -1) {
end = string.length;
}
return whatwgEncoding.labelToName(string.substring(position, end));
}
function isSpaceCharacter(c) {
return c === 0x09 || c === 0x0A || c === 0x0C || c === 0x0D || c === 0x20;
}

63
web/node_modules/html-encoding-sniffer/package.json generated vendored Normal file
View File

@@ -0,0 +1,63 @@
{
"_from": "html-encoding-sniffer@^1.0.1",
"_id": "html-encoding-sniffer@1.0.1",
"_inBundle": false,
"_integrity": "sha1-eb96eF6klf5mFl5zQVPzY/9UN9o=",
"_location": "/html-encoding-sniffer",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "html-encoding-sniffer@^1.0.1",
"name": "html-encoding-sniffer",
"escapedName": "html-encoding-sniffer",
"rawSpec": "^1.0.1",
"saveSpec": null,
"fetchSpec": "^1.0.1"
},
"_requiredBy": [
"/jsdom"
],
"_resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-1.0.1.tgz",
"_shasum": "79bf7a785ea495fe66165e734153f363ff5437da",
"_spec": "html-encoding-sniffer@^1.0.1",
"_where": "/home/bilal/Saburly/slucajna-televizija/node_modules/jsdom",
"author": {
"name": "Domenic Denicola",
"email": "d@domenic.me",
"url": "https://domenic.me/"
},
"bugs": {
"url": "https://github.com/jsdom/html-encoding-sniffer/issues"
},
"bundleDependencies": false,
"dependencies": {
"whatwg-encoding": "^1.0.1"
},
"deprecated": false,
"description": "Sniff the encoding from a HTML byte stream",
"devDependencies": {
"eslint": "^3.8.0",
"mocha": "^3.1.2"
},
"files": [
"lib/"
],
"homepage": "https://github.com/jsdom/html-encoding-sniffer#readme",
"keywords": [
"encoding",
"html"
],
"license": "WTFPL",
"main": "lib/html-encoding-sniffer.js",
"name": "html-encoding-sniffer",
"repository": {
"type": "git",
"url": "git+https://github.com/jsdom/html-encoding-sniffer.git"
},
"scripts": {
"lint": "eslint lib test",
"test": "mocha"
},
"version": "1.0.1"
}