Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

re2

Package Overview
Dependencies
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

re2 - npm Package Compare versions

Comparing version 1.18.3 to 1.19.0

2

package.json
{
"name": "re2",
"version": "1.18.3",
"version": "1.19.0",
"description": "Bindings for RE2: fast, safe alternative to backtracking regular expression engines.",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/uhop/node-re2",

@@ -61,2 +61,3 @@ # node-re2 [![NPM version][npm-img]][npm-url]

* [`re2.sticky`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky)
* *Since 1.19.0*: [`re2.hasIndices`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/hasIndices)
* [`re2.source`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source)

@@ -356,2 +357,3 @@ * [`re2.flags`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags)

- 1.19.0 *Added `hasIndices` AKA the `d` flag. Thx, [teebu](https://github.com/teebu).*
- 1.18.3 *Fixed bug with non-matched groups. Thx, [Dan Setterquist](https://github.com/dset).*

@@ -358,0 +360,0 @@ - 1.18.2 *Reference to the binary module by its full name.*

@@ -24,5 +24,9 @@ 'use strict';

eval(t.TEST("t.unify(result, ['Quick Brown Fox Jumps', 'Brown', 'Jumps'])"));
eval(
t.TEST("t.unify(result, ['Quick Brown Fox Jumps', 'Brown', 'Jumps'])")
);
eval(t.TEST('result.index === 4'));
eval(t.TEST("result.input === 'The Quick Brown Fox Jumps Over The Lazy Dog'"));
eval(
t.TEST("result.input === 'The Quick Brown Fox Jumps Over The Lazy Dog'")
);
eval(t.TEST('re.lastIndex === 25'));

@@ -152,8 +156,16 @@ },

eval(t.TEST("t.unify(result, ['Охотник Желает Знать Где', 'Желает', 'Где'])"));
eval(
t.TEST("t.unify(result, ['Охотник Желает Знать Где', 'Желает', 'Где'])")
);
eval(t.TEST('result.index === 7'));
eval(t.TEST("result.input === 'Каждый Охотник Желает Знать Где Сидит Фазан'"));
eval(
t.TEST("result.input === 'Каждый Охотник Желает Знать Где Сидит Фазан'")
);
eval(t.TEST('re.lastIndex === 31'));
eval(t.TEST("result.input.substr(result.index) === 'Охотник Желает Знать Где Сидит Фазан'"));
eval(
t.TEST(
"result.input.substr(result.index) === 'Охотник Желает Знать Где Сидит Фазан'"
)
);
eval(t.TEST("result.input.substr(re.lastIndex) === ' Сидит Фазан'"));

@@ -253,7 +265,17 @@ },

eval(t.TEST('result.input instanceof Buffer'));
eval(t.TEST("result.input.toString() === 'Каждый Охотник Желает Знать Где Сидит Фазан'"));
eval(
t.TEST(
"result.input.toString() === 'Каждый Охотник Желает Знать Где Сидит Фазан'"
)
);
eval(t.TEST('re.lastIndex === 58'));
eval(t.TEST("result.input.toString('utf8', result.index) === 'Охотник Желает Знать Где Сидит Фазан'"));
eval(t.TEST("result.input.toString('utf8', re.lastIndex) === ' Сидит Фазан'"));
eval(
t.TEST(
"result.input.toString('utf8', result.index) === 'Охотник Желает Знать Где Сидит Фазан'"
)
);
eval(
t.TEST("result.input.toString('utf8', re.lastIndex) === ' Сидит Фазан'")
);
},

@@ -323,3 +345,5 @@

eval(t.TEST('result.index < pattern.length - 4'));
eval(t.TEST('result[0] === pattern.substr(result.index, result[0].length)'));
eval(
t.TEST('result[0] === pattern.substr(result.index, result[0].length)')
);
},

@@ -339,3 +363,61 @@

eval(t.TEST("new RE2(/a.c/s).test('a\\nc')"));
},
// hasIndices tests
function test_execHasIndices(t) {
'use strict';
eval(t.TEST("!new RE2('1').hasIndices"));
eval(t.TEST('!new RE2(/1/).hasIndices'));
var re = new RE2('(aa)(?<b>b)?(?<c>ccc)', 'd');
eval(t.TEST('re.hasIndices'));
var result = re.exec('1aabccc2');
eval(t.TEST('result.length === 4'));
eval(t.TEST("result.input === '1aabccc2'"));
eval(t.TEST('result.index === 1'));
eval(t.TEST('Object.keys(result.groups).length === 2'));
eval(t.TEST("result.groups.b === 'b'"));
eval(t.TEST("result.groups.c === 'ccc'"));
eval(t.TEST("result[0] === 'aabccc'"));
eval(t.TEST("result[1] === 'aa'"));
eval(t.TEST("result[2] === 'b'"));
eval(t.TEST("result[3] === 'ccc'"));
eval(t.TEST('result.indices.length === 4'));
eval(t.TEST('t.unify(result.indices, [[1, 7], [1, 3], [3, 4], [4, 7]])'));
eval(t.TEST('Object.keys(result.indices.groups).length === 2'));
eval(t.TEST('t.unify(result.indices.groups.b, [3, 4])'));
eval(t.TEST('t.unify(result.indices.groups.c, [4, 7])'));
result = re.exec('1aaccc2');
eval(t.TEST('result.length === 4'));
eval(t.TEST("result.input === '1aaccc2'"));
eval(t.TEST('result.index === 1'));
eval(t.TEST('Object.keys(result.groups).length === 2'));
eval(t.TEST('result.groups.b === undefined'));
eval(t.TEST("result.groups.c === 'ccc'"));
eval(t.TEST("result[0] === 'aaccc'"));
eval(t.TEST("result[1] === 'aa'"));
eval(t.TEST('result[2] === undefined'));
eval(t.TEST("result[3] === 'ccc'"));
eval(t.TEST('result.indices.length === 4'));
eval(
t.TEST('t.unify(result.indices, [[1, 6], [1, 3], undefined, [3, 6]])')
);
eval(t.TEST('Object.keys(result.indices.groups).length === 2'));
eval(t.TEST('t.unify(result.indices.groups.b, undefined)'));
eval(t.TEST('t.unify(result.indices.groups.c, [3, 6])'));
try {
re = new RE2(new RegExp('1', 'd'));
eval(t.TEST('re.hasIndices'));
} catch (e) {
// squelch
}
}
]);

@@ -1,137 +0,161 @@

"use strict";
'use strict';
var unit = require('heya-unit');
var RE2 = require('../re2');
var unit = require("heya-unit");
var RE2 = require("../re2");
// tests
unit.add(module, [
// These tests are copied from MDN:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match
// These tests are copied from MDN:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match
function test_match(t) {
'use strict';
function test_match(t) {
"use strict";
var str = 'For more information, see Chapter 3.4.5.1';
var str = "For more information, see Chapter 3.4.5.1";
var re = new RE2(/(chapter \d+(\.\d)*)/i);
var result = re.match(str);
var re = new RE2(/(chapter \d+(\.\d)*)/i);
var result = re.match(str);
eval(t.TEST('result.input === str'));
eval(t.TEST('result.index === 26'));
eval(t.TEST('result.length === 3'));
eval(t.TEST("result[0] === 'Chapter 3.4.5.1'"));
eval(t.TEST("result[1] === 'Chapter 3.4.5.1'"));
eval(t.TEST("result[2] === '.1'"));
},
function test_matchGlobal(t) {
'use strict';
eval(t.TEST("result.input === str"));
eval(t.TEST("result.index === 26"));
eval(t.TEST("result.length === 3"));
eval(t.TEST("result[0] === 'Chapter 3.4.5.1'"));
eval(t.TEST("result[1] === 'Chapter 3.4.5.1'"));
eval(t.TEST("result[2] === '.1'"));
},
function test_matchGlobal(t) {
"use strict";
var re = new RE2(/[A-E]/gi);
var result = re.match(
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
);
var re = new RE2(/[A-E]/gi);
var result = re.match("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
eval(
t.TEST(
"t.unify(result, ['A', 'B', 'C', 'D', 'E', 'a', 'b', 'c', 'd', 'e'])"
)
);
},
function test_matchFail(t) {
'use strict';
eval(t.TEST("t.unify(result, ['A', 'B', 'C', 'D', 'E', 'a', 'b', 'c', 'd', 'e'])"));
},
function test_matchFail(t) {
"use strict";
var re = new RE2('(a+)?(b+)?');
var result = re.match('aaabb');
var re = new RE2("(a+)?(b+)?");
var result = re.match("aaabb");
eval(t.TEST("result[1] === 'aaa'"));
eval(t.TEST("result[2] === 'bb'"));
eval(t.TEST("result[1] === 'aaa'"));
eval(t.TEST("result[2] === 'bb'"));
result = re.match('aaacbb');
result = re.match("aaacbb");
eval(t.TEST("result[1] === 'aaa'"));
eval(t.TEST('result[2] === undefined'));
},
function test_matchInvalid(t) {
'use strict';
eval(t.TEST("result[1] === 'aaa'"));
eval(t.TEST("result[2] === undefined"));
},
function test_matchInvalid(t) {
"use strict";
var re = RE2('');
var re = RE2('');
try {
re.match({
toString() {
throw 'corner';
}
});
t.test(false); // shouldn't be here
} catch (e) {
eval(t.TEST("e === 'corner'"));
}
},
try {
re.match({ toString() { throw "corner"; } });
t.test(false); // shouldn't be here
} catch(e) {
eval(t.TEST("e === 'corner'"));
}
},
// Unicode tests
// Unicode tests
function test_matchUnicode(t) {
'use strict';
function test_matchUnicode(t) {
"use strict";
var str = 'Это ГЛАВА 3.4.5.1';
var str = "Это ГЛАВА 3.4.5.1";
var re = new RE2(/(глава \d+(\.\d)*)/i);
var result = re.match(str);
var re = new RE2(/(глава \d+(\.\d)*)/i);
var result = re.match(str);
eval(t.TEST('result.input === str'));
eval(t.TEST('result.index === 4'));
eval(t.TEST('result.length === 3'));
eval(t.TEST("result[0] === 'ГЛАВА 3.4.5.1'"));
eval(t.TEST("result[1] === 'ГЛАВА 3.4.5.1'"));
eval(t.TEST("result[2] === '.1'"));
},
eval(t.TEST("result.input === str"));
eval(t.TEST("result.index === 4"));
eval(t.TEST("result.length === 3"));
eval(t.TEST("result[0] === 'ГЛАВА 3.4.5.1'"));
eval(t.TEST("result[1] === 'ГЛАВА 3.4.5.1'"));
eval(t.TEST("result[2] === '.1'"));
},
// Buffer tests
// Buffer tests
function test_matchBuffer(t) {
'use strict';
function test_matchBuffer(t) {
"use strict";
var buf = new Buffer('Это ГЛАВА 3.4.5.1');
var buf = new Buffer("Это ГЛАВА 3.4.5.1");
var re = new RE2(/(глава \d+(\.\d)*)/i);
var result = re.match(buf);
var re = new RE2(/(глава \d+(\.\d)*)/i);
var result = re.match(buf);
eval(t.TEST('result.input instanceof Buffer'));
eval(t.TEST('result.length === 3'));
eval(t.TEST('result[0] instanceof Buffer'));
eval(t.TEST('result[1] instanceof Buffer'));
eval(t.TEST('result[2] instanceof Buffer'));
eval(t.TEST("result.input instanceof Buffer"));
eval(t.TEST("result.length === 3"));
eval(t.TEST("result[0] instanceof Buffer"));
eval(t.TEST("result[1] instanceof Buffer"));
eval(t.TEST("result[2] instanceof Buffer"));
eval(t.TEST('result.input === buf'));
eval(t.TEST('result.index === 7'));
eval(
t.TEST("result.input.toString('utf8', result.index) === 'ГЛАВА 3.4.5.1'")
);
eval(t.TEST("result[0].toString() === 'ГЛАВА 3.4.5.1'"));
eval(t.TEST("result[1].toString() === 'ГЛАВА 3.4.5.1'"));
eval(t.TEST("result[2].toString() === '.1'"));
},
eval(t.TEST("result.input === buf"));
eval(t.TEST("result.index === 7"));
eval(t.TEST("result.input.toString('utf8', result.index) === 'ГЛАВА 3.4.5.1'"));
eval(t.TEST("result[0].toString() === 'ГЛАВА 3.4.5.1'"));
eval(t.TEST("result[1].toString() === 'ГЛАВА 3.4.5.1'"));
eval(t.TEST("result[2].toString() === '.1'"));
},
// Sticky tests
// Sticky tests
function test_matchSticky(t) {
'use strict';
function test_matchSticky(t) {
"use strict";
var re = new RE2('\\s+', 'y');
var re = new RE2("\\s+", "y");
eval(t.TEST("re.match('Hello world, how are you?') === null"));
eval(t.TEST("re.match('Hello world, how are you?') === null"));
re.lastIndex = 5;
re.lastIndex = 5;
var result = re.match('Hello world, how are you?');
var result = re.match("Hello world, how are you?");
eval(t.TEST("t.unify(result, [' '])"));
eval(t.TEST('result.index === 5'));
eval(t.TEST('re.lastIndex === 6'));
eval(t.TEST("t.unify(result, [' '])"));
eval(t.TEST("result.index === 5"));
eval(t.TEST("re.lastIndex === 6"));
var re2 = new RE2('\\s+', 'gy');
var re2 = new RE2("\\s+", "gy");
eval(t.TEST("re2.match('Hello world, how are you?') === null"));
eval(t.TEST("re2.match('Hello world, how are you?') === null"));
re2.lastIndex = 5;
re2.lastIndex = 5;
eval(t.TEST("re2.match('Hello world, how are you?') === null"));
eval(t.TEST("re2.match('Hello world, how are you?') === null"));
var re3 = new RE2(/[A-E]/giy);
var result3 = re3.match(
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
);
var re3 = new RE2(/[A-E]/giy);
var result3 = re3.match("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
eval(t.TEST("t.unify(result3, ['A', 'B', 'C', 'D', 'E'])"));
},
eval(t.TEST("t.unify(result3, ['A', 'B', 'C', 'D', 'E'])"));
}
// hasIndices tests
function test_matchHasIndices(t) {
'use strict';
var re = new RE2('(aa)(?<b>b)?(?<c>ccc)', 'd'),
str1 = '1aabccc2',
str2 = '1aaccc2';
eval(t.TEST("t.unify(str1.match(re), re.exec(str1))"));
eval(t.TEST("t.unify(str2.match(re), re.exec(str2))"));
}
]);

@@ -16,3 +16,6 @@ 'use strict';

var re = new RE2(/apples/gi);
var result = re.replace('Apples are round, and apples are juicy.', 'oranges');
var result = re.replace(
'Apples are round, and apples are juicy.',
'oranges'
);
eval(t.TEST("result === 'oranges are round, and oranges are juicy.'"));

@@ -203,11 +206,20 @@

var re = new RE2(/яблоки/gi);
var result = re.replace(new Buffer('Яблоки красны, яблоки сочны.'), 'апельсины');
var result = re.replace(
new Buffer('Яблоки красны, яблоки сочны.'),
'апельсины'
);
eval(t.TEST('result instanceof Buffer'));
eval(t.TEST("result.toString() === 'апельсины красны, апельсины сочны.'"));
result = re.replace(new Buffer('Яблоки красны, яблоки сочны.'), new Buffer('апельсины'));
result = re.replace(
new Buffer('Яблоки красны, яблоки сочны.'),
new Buffer('апельсины')
);
eval(t.TEST('result instanceof Buffer'));
eval(t.TEST("result.toString() === 'апельсины красны, апельсины сочны.'"));
result = re.replace('Яблоки красны, яблоки сочны.', new Buffer('апельсины'));
result = re.replace(
'Яблоки красны, яблоки сочны.',
new Buffer('апельсины')
);
eval(t.TEST("typeof result == 'string'"));

@@ -289,3 +301,3 @@ eval(t.TEST("result === 'апельсины красны, апельсины сочны.'"));

function test_ReplaceOneNonMatch(t) {
function test_replaceOneNonMatch(t) {
'use strict';

@@ -306,6 +318,6 @@

},
function test_ReplaceTwoNonMatches(t) {
function test_replaceTwoNonMatches(t) {
'use strict';
function replacer(match, capture1, capture2, offset, string) {
function replacer(match, capture1, capture2, offset, string, groups) {
t.test(typeof offset == 'number');

@@ -319,6 +331,10 @@ t.test(typeof match == 'string');

t.test(string === 'ab & yz');
t.test(typeof groups == 'object');
t.test(Object.keys(groups).length == 2);
t.test(groups.a === undefined);
t.test(groups.b == undefined);
return '';
}
var re = new RE2(/b(1)? & (2)?y/);
var re = new RE2(/b(?<a>1)? & (?<b>2)?y/);
var result = re.replace('ab & yz', replacer);

@@ -325,0 +341,0 @@ eval(t.TEST("result === 'az'"));

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