Update Node_modules
This commit is contained in:
-17
@@ -1,17 +0,0 @@
|
||||
{
|
||||
"plugins": [
|
||||
"prettier"
|
||||
],
|
||||
"env": {
|
||||
"browser": true,
|
||||
"node": true,
|
||||
"es6": true
|
||||
},
|
||||
"rules": {
|
||||
"prettier/prettier": ["error", {
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "es5"
|
||||
}]
|
||||
}
|
||||
}
|
||||
+5
@@ -3,3 +3,8 @@ language: node_js
|
||||
node_js:
|
||||
- "6"
|
||||
- "8"
|
||||
- "10"
|
||||
- "12"
|
||||
|
||||
before_install:
|
||||
- npm install -g npm@6
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
# Change Log
|
||||
All notable changes to the "saslprep" package will be documented in this file.
|
||||
|
||||
## [1.0.3] - 2019-05-01
|
||||
|
||||
- Correctly get code points >U+FFFF ([#5](https://github.com/reklatsmasters/saslprep/pull/5))
|
||||
- Fix perfomance downgrades from [#5](https://github.com/reklatsmasters/saslprep/pull/5).
|
||||
|
||||
## [1.0.2] - 2018-09-13
|
||||
|
||||
- Reduced initialization time ([#3](https://github.com/reklatsmasters/saslprep/issues/3))
|
||||
|
||||
## [1.0.1] - 2018-06-20
|
||||
|
||||
- Reduced stack overhead of range creation ([#2](https://github.com/reklatsmasters/saslprep/pull/2))
|
||||
|
||||
## [1.0.0] - 2017-06-21
|
||||
|
||||
- First release
|
||||
+7
-4
@@ -11,16 +11,19 @@ const bidirectional_r_al = bitfield();
|
||||
const bidirectional_l = bitfield();
|
||||
|
||||
/**
|
||||
* Iterare over code points and
|
||||
* convert it into an buffer.
|
||||
* @param {bitfield} bits
|
||||
* @param {array} src
|
||||
* @param {Array} src
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
function traverse(bits, src) {
|
||||
for(const code of src.keys()) {
|
||||
for (const code of src.keys()) {
|
||||
bits.set(code, true);
|
||||
}
|
||||
|
||||
const buffer = bits.toBuffer();
|
||||
return Buffer.concat([ createSize(buffer), buffer ]);
|
||||
return Buffer.concat([createSize(buffer), buffer]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,7 +45,7 @@ memory.push(
|
||||
traverse(non_ascii_space_characters, codePoints.non_ASCII_space_characters),
|
||||
traverse(prohibited_characters, codePoints.prohibited_characters),
|
||||
traverse(bidirectional_r_al, codePoints.bidirectional_r_al),
|
||||
traverse(bidirectional_l, codePoints.bidirectional_l),
|
||||
traverse(bidirectional_l, codePoints.bidirectional_l)
|
||||
);
|
||||
|
||||
process.stdout.write(Buffer.concat(memory));
|
||||
|
||||
+69
-32
@@ -1,4 +1,4 @@
|
||||
'use strict'
|
||||
'use strict';
|
||||
|
||||
const {
|
||||
unassigned_code_points,
|
||||
@@ -7,9 +7,9 @@ const {
|
||||
prohibited_characters,
|
||||
bidirectional_r_al,
|
||||
bidirectional_l,
|
||||
} = require('./lib/memory-code-points')
|
||||
} = require('./lib/memory-code-points');
|
||||
|
||||
module.exports = saslprep
|
||||
module.exports = saslprep;
|
||||
|
||||
// 2.1. Mapping
|
||||
|
||||
@@ -17,87 +17,120 @@ module.exports = saslprep
|
||||
* non-ASCII space characters [StringPrep, C.1.2] that can be
|
||||
* mapped to SPACE (U+0020)
|
||||
*/
|
||||
const mapping2space = non_ASCII_space_characters
|
||||
const mapping2space = non_ASCII_space_characters;
|
||||
|
||||
/**
|
||||
* the "commonly mapped to nothing" characters [StringPrep, B.1]
|
||||
* that can be mapped to nothing.
|
||||
*/
|
||||
const mapping2nothing = commonly_mapped_to_nothing
|
||||
const mapping2nothing = commonly_mapped_to_nothing;
|
||||
|
||||
// utils
|
||||
const getCodePoint = character => character.codePointAt(0)
|
||||
const first = x => x[0]
|
||||
const last = x => x[x.length - 1]
|
||||
const getCodePoint = character => character.codePointAt(0);
|
||||
const first = x => x[0];
|
||||
const last = x => x[x.length - 1];
|
||||
|
||||
/**
|
||||
* Convert provided string into an array of Unicode Code Points.
|
||||
* Based on https://stackoverflow.com/a/21409165/1556249
|
||||
* and https://www.npmjs.com/package/code-point-at.
|
||||
* @param {string} input
|
||||
* @returns {number[]}
|
||||
*/
|
||||
function toCodePoints(input) {
|
||||
const codepoints = [];
|
||||
const size = input.length;
|
||||
|
||||
for (let i = 0; i < size; i += 1) {
|
||||
const before = input.charCodeAt(i);
|
||||
|
||||
if (before >= 0xd800 && before <= 0xdbff && size > i + 1) {
|
||||
const next = input.charCodeAt(i + 1);
|
||||
|
||||
if (next >= 0xdc00 && next <= 0xdfff) {
|
||||
codepoints.push((before - 0xd800) * 0x400 + next - 0xdc00 + 0x10000);
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
codepoints.push(before);
|
||||
}
|
||||
|
||||
return codepoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* SASLprep.
|
||||
* @param {string} input
|
||||
* @param {object} opts
|
||||
* @param {Object} opts
|
||||
* @param {boolean} opts.allowUnassigned
|
||||
* @returns {string}
|
||||
*/
|
||||
function saslprep(input, opts = {}) {
|
||||
if (typeof input !== 'string') {
|
||||
throw new TypeError('Expected string.')
|
||||
throw new TypeError('Expected string.');
|
||||
}
|
||||
|
||||
if (input.length === 0) {
|
||||
return ''
|
||||
return '';
|
||||
}
|
||||
|
||||
// 1. Map
|
||||
const mapped_input = input
|
||||
.split('')
|
||||
.map(getCodePoint)
|
||||
const mapped_input = toCodePoints(input)
|
||||
// 1.1 mapping to space
|
||||
.map(character => (mapping2space.get(character) ? 0x20 : character))
|
||||
// 1.2 mapping to nothing
|
||||
.filter(character => !mapping2nothing.get(character))
|
||||
.filter(character => !mapping2nothing.get(character));
|
||||
|
||||
// 2. Normalize
|
||||
const normalized_input = String.fromCodePoint(...mapped_input).normalize('NFKC')
|
||||
const normalized_input = String.fromCodePoint
|
||||
.apply(null, mapped_input)
|
||||
.normalize('NFKC');
|
||||
|
||||
const normalized_map = normalized_input.split('').map(getCodePoint)
|
||||
const normalized_map = toCodePoints(normalized_input);
|
||||
|
||||
// 3. Prohibit
|
||||
const hasProhibited = normalized_map.some(character =>
|
||||
prohibited_characters.get(character)
|
||||
)
|
||||
);
|
||||
|
||||
if (hasProhibited) {
|
||||
throw new Error(
|
||||
'Prohibited character, see https://tools.ietf.org/html/rfc4013#section-2.3'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Unassigned Code Points
|
||||
if (opts.allowUnassigned !== true) {
|
||||
const hasUnassigned = normalized_map.some(character =>
|
||||
unassigned_code_points.get(character)
|
||||
)
|
||||
);
|
||||
|
||||
if (hasUnassigned) {
|
||||
throw new Error(
|
||||
'Unassigned code point, see https://tools.ietf.org/html/rfc4013#section-2.5'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 4. check bidi
|
||||
|
||||
const hasBidiRAL = normalized_map
|
||||
.some((character) => bidirectional_r_al.get(character))
|
||||
const hasBidiRAL = normalized_map.some(character =>
|
||||
bidirectional_r_al.get(character)
|
||||
);
|
||||
|
||||
const hasBidiL = normalized_map
|
||||
.some((character) => bidirectional_l.get(character))
|
||||
const hasBidiL = normalized_map.some(character =>
|
||||
bidirectional_l.get(character)
|
||||
);
|
||||
|
||||
// 4.1 If a string contains any RandALCat character, the string MUST NOT
|
||||
// contain any LCat character.
|
||||
if (hasBidiRAL && hasBidiL) {
|
||||
throw new Error(
|
||||
'String must not contain RandALCat and LCat at the same time,' +
|
||||
' see https://tools.ietf.org/html/rfc3454#section-6'
|
||||
)
|
||||
' see https://tools.ietf.org/html/rfc3454#section-6'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,15 +139,19 @@ function saslprep(input, opts = {}) {
|
||||
* RandALCat character MUST be the last character of the string.
|
||||
*/
|
||||
|
||||
const isFirstBidiRAL = bidirectional_r_al.get(getCodePoint(first(normalized_input)))
|
||||
const isLastBidiRAL = bidirectional_r_al.get(getCodePoint(last(normalized_input)))
|
||||
const isFirstBidiRAL = bidirectional_r_al.get(
|
||||
getCodePoint(first(normalized_input))
|
||||
);
|
||||
const isLastBidiRAL = bidirectional_r_al.get(
|
||||
getCodePoint(last(normalized_input))
|
||||
);
|
||||
|
||||
if (hasBidiRAL && !(isFirstBidiRAL && isLastBidiRAL)) {
|
||||
throw new Error(
|
||||
'Bidirectional RandALCat character must be the first and the last' +
|
||||
' character of the string, see https://tools.ietf.org/html/rfc3454#section-6'
|
||||
)
|
||||
' character of the string, see https://tools.ietf.org/html/rfc3454#section-6'
|
||||
);
|
||||
}
|
||||
|
||||
return normalized_input
|
||||
return normalized_input;
|
||||
}
|
||||
|
||||
+788
-788
File diff suppressed because it is too large
Load Diff
+6
-1
@@ -4,9 +4,14 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const bitfield = require('sparse-bitfield');
|
||||
|
||||
/* eslint-disable-next-line security/detect-non-literal-fs-filename */
|
||||
const memory = fs.readFileSync(path.resolve(__dirname, '../code-points.mem'));
|
||||
let offset = 0;
|
||||
|
||||
/**
|
||||
* Loads each code points sequence from buffer.
|
||||
* @returns {bitfield}
|
||||
*/
|
||||
function read() {
|
||||
const size = memory.readUInt32BE(offset);
|
||||
offset += 4;
|
||||
@@ -31,4 +36,4 @@ module.exports = {
|
||||
prohibited_characters,
|
||||
bidirectional_r_al,
|
||||
bidirectional_l,
|
||||
}
|
||||
};
|
||||
|
||||
+13
-7
@@ -1,15 +1,21 @@
|
||||
'use strict'
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Create an array of numbers.
|
||||
* @param {number} from
|
||||
* @param {number} to
|
||||
* @returns {number[]}
|
||||
*/
|
||||
function range(from, to) {
|
||||
// TODO: make this inlined.
|
||||
const list = new Array(to - from + 1)
|
||||
const list = new Array(to - from + 1);
|
||||
|
||||
for(let i = 0; i < list.length; ++i) {
|
||||
list[i] = from + i
|
||||
for (let i = 0; i < list.length; i += 1) {
|
||||
list[i] = from + i;
|
||||
}
|
||||
return list
|
||||
return list;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
range
|
||||
}
|
||||
range,
|
||||
};
|
||||
|
||||
+44
-10
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"_from": "saslprep@^1.0.0",
|
||||
"_id": "saslprep@1.0.2",
|
||||
"_id": "saslprep@1.0.3",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-4cDsYuAjXssUSjxHKRe4DTZC0agDwsCqcMqtJAQPzC74nJ7LfAJflAtC1Zed5hMzEQKj82d3tuzqdGNRsLJ4Gw==",
|
||||
"_integrity": "sha512-/MY/PEMbk2SuY5sScONwhUDsV2p77Znkb/q3nSVstq/yQzYJOH/Azh29p9oJLsl3LnQwSvZDKagDGBsBwSooag==",
|
||||
"_location": "/saslprep",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
@@ -18,10 +18,10 @@
|
||||
"_requiredBy": [
|
||||
"/mongodb-core"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/saslprep/-/saslprep-1.0.2.tgz",
|
||||
"_shasum": "da5ab936e6ea0bbae911ffec77534be370c9f52d",
|
||||
"_resolved": "https://registry.npmjs.org/saslprep/-/saslprep-1.0.3.tgz",
|
||||
"_shasum": "4c02f946b56cf54297e347ba1093e7acac4cf226",
|
||||
"_spec": "saslprep@^1.0.0",
|
||||
"_where": "D:\\Gitterra\\om\\node_modules\\mongodb-core",
|
||||
"_where": "/home/erik/Documents/workspace_brackets/a1_BME_Project_Ohm/om/node_modules/mongodb-core",
|
||||
"author": {
|
||||
"name": "Dmitry Tsvettsikh",
|
||||
"email": "me@reklatsmasters.com"
|
||||
@@ -36,14 +36,46 @@
|
||||
"deprecated": false,
|
||||
"description": "SASLprep: Stringprep Profile for User Names and Passwords, rfc4013.",
|
||||
"devDependencies": {
|
||||
"ava": "^0.25.0",
|
||||
"eslint-plugin-prettier": "^2.1.2",
|
||||
"prettier": "^1.4.4"
|
||||
"@nodertc/eslint-config": "^0.2.1",
|
||||
"eslint": "^5.16.0",
|
||||
"jest": "^23.6.0",
|
||||
"prettier": "^1.14.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "@nodertc",
|
||||
"rules": {
|
||||
"camelcase": "off",
|
||||
"no-continue": "off"
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"files": [
|
||||
"test/*.js"
|
||||
],
|
||||
"env": {
|
||||
"jest": true
|
||||
},
|
||||
"rules": {
|
||||
"require-jsdoc": "off"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"homepage": "https://github.com/reklatsmasters/saslprep#readme",
|
||||
"jest": {
|
||||
"modulePaths": [
|
||||
"<rootDir>"
|
||||
],
|
||||
"testMatch": [
|
||||
"**/test/*.js"
|
||||
],
|
||||
"testPathIgnorePatterns": [
|
||||
"<rootDir>/node_modules/"
|
||||
]
|
||||
},
|
||||
"keywords": [
|
||||
"sasl",
|
||||
"saslprep",
|
||||
@@ -60,7 +92,9 @@
|
||||
},
|
||||
"scripts": {
|
||||
"gen-code-points": "node generate-code-points.js > code-points.mem",
|
||||
"test": "ava"
|
||||
"lint": "npx eslint --quiet .",
|
||||
"test": "npm run lint && npm run unit-test",
|
||||
"unit-test": "npx jest"
|
||||
},
|
||||
"version": "1.0.2"
|
||||
"version": "1.0.3"
|
||||
}
|
||||
|
||||
+1
-1
@@ -28,4 +28,4 @@ A special behavior for unassigned code points, see https://tools.ietf.org/html/r
|
||||
|
||||
## License
|
||||
|
||||
MIT, 2017 (c) Dmitriy Tsvettsikh
|
||||
MIT, 2017-2019 (c) Dmitriy Tsvettsikh
|
||||
|
||||
+49
-43
@@ -1,70 +1,76 @@
|
||||
import test from 'ava'
|
||||
import saslprep from '../'
|
||||
'use strict';
|
||||
|
||||
const chr = String.fromCodePoint
|
||||
const saslprep = require('..');
|
||||
|
||||
test('should work with liatin letters', (t) => {
|
||||
const str = 'user'
|
||||
t.is(saslprep(str), str)
|
||||
})
|
||||
const chr = String.fromCodePoint;
|
||||
|
||||
test('should work be case preserved', (t) => {
|
||||
const str = 'USER'
|
||||
t.is(saslprep(str), str)
|
||||
})
|
||||
test('should work with liatin letters', () => {
|
||||
const str = 'user';
|
||||
expect(saslprep(str)).toEqual(str);
|
||||
});
|
||||
|
||||
test('should remove `mapped to nothing` characters', (t) => {
|
||||
t.is(saslprep('I\u00ADX'), 'IX')
|
||||
})
|
||||
test('should work be case preserved', () => {
|
||||
const str = 'USER';
|
||||
expect(saslprep(str)).toEqual(str);
|
||||
});
|
||||
|
||||
test('should replace `Non-ASCII space characters` with space', (t) => {
|
||||
t.is(saslprep('a\u00A0b'), 'a\u0020b')
|
||||
})
|
||||
test('should work with high code points (> U+FFFF)', () => {
|
||||
const str = '\uD83D\uDE00';
|
||||
expect(saslprep(str, { allowUnassigned: true })).toEqual(str);
|
||||
});
|
||||
|
||||
test('should normalize as NFKC', (t) => {
|
||||
t.is(saslprep('\u00AA'), 'a')
|
||||
t.is(saslprep('\u2168'), 'IX')
|
||||
})
|
||||
test('should remove `mapped to nothing` characters', () => {
|
||||
expect(saslprep('I\u00ADX')).toEqual('IX');
|
||||
});
|
||||
|
||||
test('should throws when prohibited characters', (t) => {
|
||||
test('should replace `Non-ASCII space characters` with space', () => {
|
||||
expect(saslprep('a\u00A0b')).toEqual('a\u0020b');
|
||||
});
|
||||
|
||||
test('should normalize as NFKC', () => {
|
||||
expect(saslprep('\u00AA')).toEqual('a');
|
||||
expect(saslprep('\u2168')).toEqual('IX');
|
||||
});
|
||||
|
||||
test('should throws when prohibited characters', () => {
|
||||
// C.2.1 ASCII control characters
|
||||
t.throws(() => saslprep('a\u007Fb'))
|
||||
expect(() => saslprep('a\u007Fb')).toThrow();
|
||||
|
||||
// C.2.2 Non-ASCII control characters
|
||||
t.throws(() => saslprep('a\u06DDb'))
|
||||
expect(() => saslprep('a\u06DDb')).toThrow();
|
||||
|
||||
// C.3 Private use
|
||||
t.throws(() => saslprep('a\uE000b'))
|
||||
expect(() => saslprep('a\uE000b')).toThrow();
|
||||
|
||||
// C.4 Non-character code points
|
||||
t.throws(() => saslprep(`a${chr(0x1FFFE)}b`))
|
||||
expect(() => saslprep(`a${chr(0x1fffe)}b`)).toThrow();
|
||||
|
||||
// C.5 Surrogate codes
|
||||
t.throws(() => saslprep('a\uD800b'))
|
||||
expect(() => saslprep('a\uD800b')).toThrow();
|
||||
|
||||
// C.6 Inappropriate for plain text
|
||||
t.throws(() => saslprep('a\uFFF9b'))
|
||||
expect(() => saslprep('a\uFFF9b')).toThrow();
|
||||
|
||||
// C.7 Inappropriate for canonical representation
|
||||
t.throws(() => saslprep('a\u2FF0b'))
|
||||
expect(() => saslprep('a\u2FF0b')).toThrow();
|
||||
|
||||
// C.8 Change display properties or are deprecated
|
||||
t.throws(() => saslprep('a\u200Eb'))
|
||||
expect(() => saslprep('a\u200Eb')).toThrow();
|
||||
|
||||
// C.9 Tagging characters
|
||||
t.throws(() => saslprep(`a${chr(0xE0001)}b`))
|
||||
})
|
||||
expect(() => saslprep(`a${chr(0xe0001)}b`)).toThrow();
|
||||
});
|
||||
|
||||
test('should not containt RandALCat and LCat bidi', (t) => {
|
||||
t.throws(() => saslprep('a\u06DD\u00AAb'))
|
||||
})
|
||||
test('should not containt RandALCat and LCat bidi', () => {
|
||||
expect(() => saslprep('a\u06DD\u00AAb')).toThrow();
|
||||
});
|
||||
|
||||
test('RandALCat should be first and last', (t) => {
|
||||
t.notThrows(() => saslprep('\u0627\u0031\u0628'))
|
||||
t.throws(() => saslprep('\u0627\u0031'))
|
||||
})
|
||||
test('RandALCat should be first and last', () => {
|
||||
expect(() => saslprep('\u0627\u0031\u0628')).not.toThrow();
|
||||
expect(() => saslprep('\u0627\u0031')).toThrow();
|
||||
});
|
||||
|
||||
test('should handle unassigned code points', (t) => {
|
||||
t.throws(() => saslprep('a\u0487'))
|
||||
t.notThrows(() => saslprep('a\u0487', {allowUnassigned: true}))
|
||||
})
|
||||
test('should handle unassigned code points', () => {
|
||||
expect(() => saslprep('a\u0487')).toThrow();
|
||||
expect(() => saslprep('a\u0487', { allowUnassigned: true })).not.toThrow();
|
||||
});
|
||||
|
||||
+12
-11
@@ -1,15 +1,16 @@
|
||||
import { setFlagsFromString } from 'v8'
|
||||
import { range } from '../lib/util'
|
||||
import test from 'ava'
|
||||
'use strict';
|
||||
|
||||
const { setFlagsFromString } = require('v8');
|
||||
const { range } = require('../lib/util');
|
||||
|
||||
// 984 by default.
|
||||
setFlagsFromString('--stack_size=500')
|
||||
setFlagsFromString('--stack_size=500');
|
||||
|
||||
test('should work', (t) => {
|
||||
const list = range(1, 3)
|
||||
t.deepEqual(list, [1, 2, 3])
|
||||
})
|
||||
test('should work', () => {
|
||||
const list = range(1, 3);
|
||||
expect(list).toEqual([1, 2, 3]);
|
||||
});
|
||||
|
||||
test('should work for large ranges', (t) => {
|
||||
t.notThrows(() => range(1, 1e6))
|
||||
})
|
||||
test('should work for large ranges', () => {
|
||||
expect(() => range(1, 1e6)).not.toThrow();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user