This commit is contained in:
30
node_modules/utf-8-validate/LICENSE
generated
vendored
Normal file
30
node_modules/utf-8-validate/LICENSE
generated
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
This project is licensed for use as follows:
|
||||
|
||||
"""
|
||||
Copyright (c) 2011 Einar Otto Stangvik <einaros@gmail.com> (http://2x.io)
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
"""
|
||||
|
||||
This license applies to parts originating from
|
||||
https://www.cl.cam.ac.uk/~mgk25/ucs/utf8_check.c:
|
||||
|
||||
"""
|
||||
Markus Kuhn <http://www.cl.cam.ac.uk/~mgk25/> -- 2005-03-30
|
||||
License: http://www.cl.cam.ac.uk/~mgk25/short-license.html
|
||||
"""
|
50
node_modules/utf-8-validate/README.md
generated
vendored
Normal file
50
node_modules/utf-8-validate/README.md
generated
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
# utf-8-validate
|
||||
|
||||
[](https://www.npmjs.com/package/utf-8-validate)
|
||||
[](https://github.com/websockets/utf-8-validate/actions?query=workflow%3ACI+branch%3Amaster)
|
||||
|
||||
Check if a buffer contains valid UTF-8 encoded text.
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
npm install utf-8-validate --save-optional
|
||||
```
|
||||
|
||||
The `--save-optional` flag tells npm to save the package in your package.json
|
||||
under the
|
||||
[`optionalDependencies`](https://docs.npmjs.com/files/package.json#optionaldependencies)
|
||||
key.
|
||||
|
||||
## API
|
||||
|
||||
The module exports a single function which takes one argument.
|
||||
|
||||
### `isValidUTF8(buffer)`
|
||||
|
||||
Checks whether a buffer contains valid UTF-8.
|
||||
|
||||
#### Arguments
|
||||
|
||||
- `buffer` - The buffer to check.
|
||||
|
||||
#### Return value
|
||||
|
||||
`true` if the buffer contains only correct UTF-8, else `false`.
|
||||
|
||||
#### Example
|
||||
|
||||
```js
|
||||
'use strict';
|
||||
|
||||
const isValidUTF8 = require('utf-8-validate');
|
||||
|
||||
const buf = Buffer.from([0xf0, 0x90, 0x80, 0x80]);
|
||||
|
||||
console.log(isValidUTF8(buf));
|
||||
// => true
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE)
|
18
node_modules/utf-8-validate/binding.gyp
generated
vendored
Normal file
18
node_modules/utf-8-validate/binding.gyp
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
'targets': [
|
||||
{
|
||||
'target_name': 'validation',
|
||||
'sources': ['src/validation.c'],
|
||||
'cflags': ['-std=c99'],
|
||||
'conditions': [
|
||||
["OS=='mac'", {
|
||||
'xcode_settings': {
|
||||
'MACOSX_DEPLOYMENT_TARGET': '10.7',
|
||||
'OTHER_CFLAGS': ['-arch x86_64', '-arch arm64'],
|
||||
'OTHER_LDFLAGS': ['-arch x86_64', '-arch arm64']
|
||||
}
|
||||
}]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
62
node_modules/utf-8-validate/fallback.js
generated
vendored
Normal file
62
node_modules/utf-8-validate/fallback.js
generated
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Checks if a given buffer contains only correct UTF-8.
|
||||
* Ported from https://www.cl.cam.ac.uk/%7Emgk25/ucs/utf8_check.c by
|
||||
* Markus Kuhn.
|
||||
*
|
||||
* @param {Buffer} buf The buffer to check
|
||||
* @return {Boolean} `true` if `buf` contains only correct UTF-8, else `false`
|
||||
* @public
|
||||
*/
|
||||
function isValidUTF8(buf) {
|
||||
const len = buf.length;
|
||||
let i = 0;
|
||||
|
||||
while (i < len) {
|
||||
if ((buf[i] & 0x80) === 0x00) { // 0xxxxxxx
|
||||
i++;
|
||||
} else if ((buf[i] & 0xe0) === 0xc0) { // 110xxxxx 10xxxxxx
|
||||
if (
|
||||
i + 1 === len ||
|
||||
(buf[i + 1] & 0xc0) !== 0x80 ||
|
||||
(buf[i] & 0xfe) === 0xc0 // overlong
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
i += 2;
|
||||
} else if ((buf[i] & 0xf0) === 0xe0) { // 1110xxxx 10xxxxxx 10xxxxxx
|
||||
if (
|
||||
i + 2 >= len ||
|
||||
(buf[i + 1] & 0xc0) !== 0x80 ||
|
||||
(buf[i + 2] & 0xc0) !== 0x80 ||
|
||||
buf[i] === 0xe0 && (buf[i + 1] & 0xe0) === 0x80 || // overlong
|
||||
buf[i] === 0xed && (buf[i + 1] & 0xe0) === 0xa0 // surrogate (U+D800 - U+DFFF)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
i += 3;
|
||||
} else if ((buf[i] & 0xf8) === 0xf0) { // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
if (
|
||||
i + 3 >= len ||
|
||||
(buf[i + 1] & 0xc0) !== 0x80 ||
|
||||
(buf[i + 2] & 0xc0) !== 0x80 ||
|
||||
(buf[i + 3] & 0xc0) !== 0x80 ||
|
||||
buf[i] === 0xf0 && (buf[i + 1] & 0xf0) === 0x80 || // overlong
|
||||
buf[i] === 0xf4 && buf[i + 1] > 0x8f || buf[i] > 0xf4 // > U+10FFFF
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
i += 4;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = isValidUTF8;
|
7
node_modules/utf-8-validate/index.js
generated
vendored
Normal file
7
node_modules/utf-8-validate/index.js
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
try {
|
||||
module.exports = require('node-gyp-build')(__dirname);
|
||||
} catch (e) {
|
||||
module.exports = require('./fallback');
|
||||
}
|
36
node_modules/utf-8-validate/package.json
generated
vendored
Normal file
36
node_modules/utf-8-validate/package.json
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "utf-8-validate",
|
||||
"version": "5.0.10",
|
||||
"description": "Check if a buffer contains valid UTF-8",
|
||||
"main": "index.js",
|
||||
"engines": {
|
||||
"node": ">=6.14.2"
|
||||
},
|
||||
"scripts": {
|
||||
"install": "node-gyp-build",
|
||||
"prebuild": "prebuildify --napi --strip --target=14.0.0",
|
||||
"prebuild-darwin-x64+arm64": "prebuildify --arch x64+arm64 --napi --strip --target=14.0.0",
|
||||
"test": "mocha"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/websockets/utf-8-validate"
|
||||
},
|
||||
"keywords": [
|
||||
"utf-8-validate"
|
||||
],
|
||||
"author": "Einar Otto Stangvik <einaros@gmail.com> (http://2x.io)",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/websockets/utf-8-validate/issues"
|
||||
},
|
||||
"homepage": "https://github.com/websockets/utf-8-validate",
|
||||
"dependencies": {
|
||||
"node-gyp-build": "^4.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "^10.0.0",
|
||||
"node-gyp": "^9.1.0",
|
||||
"prebuildify": "^5.0.0"
|
||||
}
|
||||
}
|
BIN
node_modules/utf-8-validate/prebuilds/darwin-x64+arm64/node.napi.node
generated
vendored
Normal file
BIN
node_modules/utf-8-validate/prebuilds/darwin-x64+arm64/node.napi.node
generated
vendored
Normal file
Binary file not shown.
BIN
node_modules/utf-8-validate/prebuilds/linux-x64/node.napi.node
generated
vendored
Normal file
BIN
node_modules/utf-8-validate/prebuilds/linux-x64/node.napi.node
generated
vendored
Normal file
Binary file not shown.
BIN
node_modules/utf-8-validate/prebuilds/win32-ia32/node.napi.node
generated
vendored
Normal file
BIN
node_modules/utf-8-validate/prebuilds/win32-ia32/node.napi.node
generated
vendored
Normal file
Binary file not shown.
BIN
node_modules/utf-8-validate/prebuilds/win32-x64/node.napi.node
generated
vendored
Normal file
BIN
node_modules/utf-8-validate/prebuilds/win32-x64/node.napi.node
generated
vendored
Normal file
Binary file not shown.
109
node_modules/utf-8-validate/src/validation.c
generated
vendored
Normal file
109
node_modules/utf-8-validate/src/validation.c
generated
vendored
Normal file
@ -0,0 +1,109 @@
|
||||
#define NAPI_VERSION 1
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <node_api.h>
|
||||
|
||||
napi_value IsValidUTF8(napi_env env, napi_callback_info info) {
|
||||
napi_status status;
|
||||
size_t argc = 1;
|
||||
napi_value argv[1];
|
||||
|
||||
status = napi_get_cb_info(env, info, &argc, argv, NULL, NULL);
|
||||
assert(status == napi_ok);
|
||||
|
||||
uint8_t *buf;
|
||||
size_t len;
|
||||
|
||||
status = napi_get_buffer_info(env, argv[0], (void **)&buf, &len);
|
||||
assert(status == napi_ok);
|
||||
|
||||
size_t i = 0;
|
||||
|
||||
//
|
||||
// This code has been taken from utf8_check.c which was developed by
|
||||
// Markus Kuhn <http://www.cl.cam.ac.uk/~mgk25/>.
|
||||
//
|
||||
// For original code / licensing please refer to
|
||||
// https://www.cl.cam.ac.uk/%7Emgk25/ucs/utf8_check.c
|
||||
//
|
||||
while (i < len) {
|
||||
size_t j = i + 8;
|
||||
|
||||
if (j <= len) {
|
||||
//
|
||||
// Read 8 bytes and check if they are ASCII.
|
||||
//
|
||||
uint64_t chunk;
|
||||
memcpy(&chunk, buf + i, 8);
|
||||
|
||||
if ((chunk & 0x8080808080808080) == 0x00) {
|
||||
i = j;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
while ((buf[i] & 0x80) == 0x00) { // 0xxxxxxx
|
||||
if (++i == len) {
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
if ((buf[i] & 0xe0) == 0xc0) { // 110xxxxx 10xxxxxx
|
||||
if (
|
||||
i + 1 == len ||
|
||||
(buf[i + 1] & 0xc0) != 0x80 ||
|
||||
(buf[i] & 0xfe) == 0xc0 // overlong
|
||||
) {
|
||||
break;
|
||||
}
|
||||
|
||||
i += 2;
|
||||
} else if ((buf[i] & 0xf0) == 0xe0) { // 1110xxxx 10xxxxxx 10xxxxxx
|
||||
if (
|
||||
i + 2 >= len ||
|
||||
(buf[i + 1] & 0xc0) != 0x80 ||
|
||||
(buf[i + 2] & 0xc0) != 0x80 ||
|
||||
(buf[i] == 0xe0 && (buf[i + 1] & 0xe0) == 0x80) || // overlong
|
||||
(buf[i] == 0xed && (buf[i + 1] & 0xe0) == 0xa0) // surrogate (U+D800 - U+DFFF)
|
||||
) {
|
||||
break;
|
||||
}
|
||||
|
||||
i += 3;
|
||||
} else if ((buf[i] & 0xf8) == 0xf0) { // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
if (
|
||||
i + 3 >= len ||
|
||||
(buf[i + 1] & 0xc0) != 0x80 ||
|
||||
(buf[i + 2] & 0xc0) != 0x80 ||
|
||||
(buf[i + 3] & 0xc0) != 0x80 ||
|
||||
(buf[i] == 0xf0 && (buf[i + 1] & 0xf0) == 0x80) || // overlong
|
||||
(buf[i] == 0xf4 && buf[i + 1] > 0x8f) || buf[i] > 0xf4 // > U+10FFFF
|
||||
) {
|
||||
break;
|
||||
}
|
||||
|
||||
i += 4;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
exit:;
|
||||
napi_value result;
|
||||
status = napi_get_boolean(env, i == len, &result);
|
||||
assert(status == napi_ok);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Init(napi_env env, napi_value exports) {
|
||||
napi_status status;
|
||||
napi_value isValidUTF8;
|
||||
|
||||
status = napi_create_function(env, NULL, 0, IsValidUTF8, NULL, &isValidUTF8);
|
||||
assert(status == napi_ok);
|
||||
|
||||
return isValidUTF8;
|
||||
}
|
||||
|
||||
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)
|
Reference in New Issue
Block a user