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

ret

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ret - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1

65

dist/tokenizer.js

@@ -39,2 +39,4 @@ "use strict";

let groupStack = [];
let referenceQueue = [];
let groupCount = 0;
const repeatErr = (col) => {

@@ -79,3 +81,10 @@ throw new SyntaxError(`Invalid regular expression: /${regexpStr}/: Nothing to repeat at column ${col - 1}`);

if (/\d/.test(c)) {
last.push({ type: types_1.types.REFERENCE, value: parseInt(c, 10) });
let digits = c;
while (/\d/.test(str[i])) {
digits += str[i++];
}
let value = parseInt(digits, 10);
const reference = { type: types_1.types.REFERENCE, value };
last.push(reference);
referenceQueue.push({ reference, stack: last, index: last.length - 1 });
// Escaped character.

@@ -147,2 +156,5 @@ }

}
else {
groupCount += 1;
}
// Insert subgroup into current group stack.

@@ -257,4 +269,55 @@ last.push(group);

}
updateReferences(referenceQueue, groupCount);
return start;
};
/**
* This is a side effecting function that changes references to chars
* if there are not enough capturing groups to reference
* See: https://github.com/fent/ret.js/pull/39#issuecomment-1006475703
* See: https://github.com/fent/ret.js/issues/38
* @param {(Reference | Char)[]} referenceQueue
* @param {number} groupCount
* @returns {void}
*/
function updateReferences(referenceQueue, groupCount) {
// Note: We go through the queue in reverse order so
// that index we use is correct even if we have to add
// multiple tokens to one stack
for (const elem of referenceQueue.reverse()) {
if (groupCount < elem.reference.value) {
// If there is nothing to reference then turn this into a char token
elem.reference.type = types_1.types.CHAR;
const valueString = elem.reference.value.toString();
// If the number is not octal then we need to create multiple tokens
// https://github.com/fent/ret.js/pull/39#issuecomment-1008229226
if (!/^[0-7]+$/.test(valueString)) {
let i = 0;
while (valueString[i] !== '8' && valueString[i] !== '9') {
i += 1;
}
if (i === 0) {
// Handling case when escaped number starts with 8 or 9
elem.reference.value = valueString.charCodeAt(0);
i += 1;
}
else {
// If the escaped number does not start with 8 or 9, then all
// 0-7 digits before the first 8/9 form the first character code
// see: https://github.com/fent/ret.js/pull/39#discussion_r780747085
elem.reference.value = parseInt(valueString.slice(0, i), 10);
}
if (valueString.length > i) {
const tail = elem.stack.splice(elem.index + 1);
for (const char of valueString.slice(i)) {
elem.stack.push({
type: types_1.types.CHAR,
value: char.charCodeAt(0),
});
}
elem.stack.push(...tail);
}
}
}
}
}
//# sourceMappingURL=tokenizer.js.map

21

dist/util.js

@@ -34,4 +34,4 @@ "use strict";

exports.strToChars = (str) => {
const charsRegex = /(\[\\b\])|(\\)?\\(?:u([A-F0-9]{4})|x([A-F0-9]{2})|(0?[0-7]{2})|c([@A-Z[\\\]^?])|([0tnvfr]))/g;
return str.replace(charsRegex, (s, b, lbs, a16, b16, c8, dctrl, eslsh) => {
const charsRegex = /(\[\\b\])|(\\)?\\(?:u([A-F0-9]{4})|x([A-F0-9]{2})|c([@A-Z[\\\]^?])|([0tnvfr]))/g;
return str.replace(charsRegex, (s, b, lbs, a16, b16, dctrl, eslsh) => {
if (lbs) {

@@ -43,11 +43,10 @@ return s;

b16 ? parseInt(b16, 16) :
c8 ? parseInt(c8, 8) :
dctrl ? CTRL.indexOf(dctrl) : {
0: 0,
t: 9,
n: 10,
v: 11,
f: 12,
r: 13,
}[eslsh];
dctrl ? CTRL.indexOf(dctrl) : {
0: 0,
t: 9,
n: 10,
v: 11,
f: 12,
r: 13,
}[eslsh];
let c = String.fromCharCode(code);

@@ -54,0 +53,0 @@ // Escape special regex characters.

@@ -11,3 +11,3 @@ {

],
"version": "0.4.0",
"version": "0.4.1",
"repository": {

@@ -14,0 +14,0 @@ "type": "git",

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