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.1.3 to 0.1.4

12

lib/index.js

@@ -8,6 +8,2 @@ var util = require('./util')

var error = function(regexp, msg) {
throw new Error('Invalid regular expression: /' + regexp + '/: ' + msg);
};
module.exports = function(regexpStr) {

@@ -24,3 +20,3 @@ var i = 0, l, c,

var repeatErr = function(i) {
error(regexpStr, 'Nothing to repeat at column ' + (i - 1));
util.error(regexpStr, 'Nothing to repeat at column ' + (i - 1));
};

@@ -110,3 +106,3 @@

// get all the characters in class
var classTokens = util.tokenizeClass(str.slice(i));
var classTokens = util.tokenizeClass(str.slice(i), regexpStr);

@@ -155,3 +151,3 @@ // increase index by length of class

} else if (c !== ':') {
error(regexpStr,
util.error(regexpStr,
'Invalid character \'' + c + '\' after \'?\' at column ' +

@@ -179,3 +175,3 @@ (i - 1));

if (groupStack.length === 0) {
error(regexpStr, 'Unmatched ) at column ' + (i - 1));
util.error(regexpStr, 'Unmatched ) at column ' + (i - 1));
}

@@ -182,0 +178,0 @@ lastGroup = groupStack.pop();

@@ -45,3 +45,3 @@ var types = require('./types')

// reads str until it encounters a ] not preceeded by a \
tokenizeClass: function(str) {
tokenizeClass: function(str, regexpStr) {
var tokens = []

@@ -89,3 +89,9 @@ , regexp = /\\(?:(w)|(d)|(s)|(W)|(D)|(S)|(.))|(.-[^\]])|(\])|(.)/g

}
util.error(regexpStr, 'Missing \']\'');
},
error: function(regexp, msg) {
throw new Error('Invalid regular expression: /' + regexp + '/: ' + msg);
}
};

@@ -5,3 +5,3 @@ {

"keywords": ["regex", "regexp", "regular expression", "parser", "tokenizer"],
"version": "0.1.3",
"version": "0.1.4",
"repository": {

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

@@ -127,3 +127,11 @@ # Regular Expression Tokenizer [![Build Status](https://secure.travis-ci.org/fent/ret.js.png)](http://travis-ci.org/fent/ret.js)

## Errors
ret.js will throw errors if given a string with an invalid regular expression. All possible errors are
* Invalid character. When a group with an immediate `?` character is followed by an invalid character. It can only be followed by `!`, `=`, or `:`. Example: `/(?$abc)/`
* Nothing to repeat. Thrown when a repetitional token is used as the first token in the current clause, as in right in the beginning of the regexp or right after a pipe. Example: `/foo|?bar/`
* Unmatched ). A group was not closed. Example: `/(1(23)4/`
* Missing ]. A custom character set was not closed. Example: `/[abc/`
# Install

@@ -130,0 +138,0 @@

@@ -54,4 +54,13 @@ var vows = require('vows')

}
},
'Bad custom character set': {
topic: macro('[abc'),
'Missing ]': function(err) {
assert.isObject(err);
assert.include(err, 'message');
assert.equal(err.message, 'Invalid regular expression: /[abc/: Missing \']\'');
}
}
})
.export(module);
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