Socket
Socket
Sign inDemoInstall

path-to-regexp

Package Overview
Dependencies
Maintainers
0
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

path-to-regexp - npm Package Compare versions

Comparing version 0.1.9 to 0.1.10

90

index.js
/**
* Expose `pathtoRegexp`.
* Expose `pathToRegexp`.
*/
module.exports = pathtoRegexp;
module.exports = pathToRegexp;

@@ -10,3 +10,3 @@ /**

*/
var MATCHING_GROUP_REGEXP = /\((?:\?<(.*?)>)?(?!\?)/g;
var MATCHING_GROUP_REGEXP = /\\.|\((?:\?<(.*?)>)?(?!\?)/g;

@@ -29,3 +29,3 @@ /**

function pathtoRegexp(path, keys, options) {
function pathToRegexp(path, keys, options) {
options = options || {};

@@ -41,2 +41,4 @@ keys = keys || [];

var name = 0;
var pos = 0;
var backtrack = '';
var m;

@@ -46,2 +48,4 @@

while (m = MATCHING_GROUP_REGEXP.exec(path.source)) {
if (m[0][0] === '\\') continue;
keys.push({

@@ -62,16 +66,43 @@ name: m[1] || name++,

path = path.map(function (value) {
return pathtoRegexp(value, keys, options).source;
return pathToRegexp(value, keys, options).source;
});
return new RegExp('(?:' + path.join('|') + ')', flags);
return new RegExp(path.join('|'), flags);
}
path = ('^' + path + (strict ? '' : path[path.length - 1] === '/' ? '?' : '/?'))
.replace(/\/\(/g, '/(?:')
.replace(/([\/\.])/g, '\\$1')
.replace(/(\\\/)?(\\\.)?:(\w+)(\(.*?\))?(\*)?(\?)?/g, function (match, slash, format, key, capture, star, optional, offset) {
path = path.replace(
/\\.|(\/)?(\.)?:(\w+)(\(.*?\))?(\*)?(\?)?|[.*]|\/\(/g,
function (match, slash, format, key, capture, star, optional, offset) {
pos = offset + match.length;
if (match[0] === '\\') {
backtrack += match;
return match;
}
if (match === '.') {
backtrack += '\\.';
extraOffset += 1;
return '\\.';
}
backtrack = slash || format ? '' : path.slice(pos, offset);
if (match === '*') {
extraOffset += 3;
return '(.*)';
}
if (match === '/(') {
backtrack += '/';
extraOffset += 2;
return '/(?:';
}
slash = slash || '';
format = format || '';
capture = capture || '([^\\/' + format + ']+?)';
format = format ? '\\.' : '';
optional = optional || '';
capture = capture ?
capture.replace(/\\.|\*/, function (m) { return m === '*' ? '(.*)' : m; }) :
(backtrack ? '((?:(?!/|' + backtrack + ').)+?)' : '([^/' + format + ']+?)');

@@ -84,7 +115,5 @@ keys.push({

var result = ''
+ (optional ? '' : slash)
+ '(?:'
+ format + (optional ? slash : '') + capture
+ (star ? '((?:[\\/' + format + '].+?)?)' : '')
var result = '(?:'
+ format + slash + capture
+ (star ? '((?:[/' + format + '].+?)?)' : '')
+ ')'

@@ -96,11 +125,2 @@ + optional;

return result;
})
.replace(/\*/g, function (star, index) {
var len = keys.length
while (len-- > keysOffset && keys[len].offset > index) {
keys[len].offset += 3; // Replacement length minus asterisk length.
}
return '(.*)';
});

@@ -110,14 +130,4 @@

while (m = MATCHING_GROUP_REGEXP.exec(path)) {
var escapeCount = 0;
var index = m.index;
if (m[0][0] === '\\') continue;
while (path.charAt(--index) === '\\') {
escapeCount++;
}
// It's possible to escape the bracket.
if (escapeCount % 2 === 1) {
continue;
}
if (keysOffset + i === keys.length || keys[keysOffset + i].offset > m.index) {

@@ -134,2 +144,4 @@ keys.splice(keysOffset + i, 0, {

path += strict ? '' : path[path.length - 1] === '/' ? '?' : '/?';
// If the path is non-ending, match until the end or a slash.

@@ -139,6 +151,6 @@ if (end) {

} else if (path[path.length - 1] !== '/') {
path += lookahead ? '(?=\\/|$)' : '(?:\/|$)';
path += lookahead ? '(?=/|$)' : '(?:/|$)';
}
return new RegExp(path, flags);
return new RegExp('^' + path, flags);
};
{
"name": "path-to-regexp",
"description": "Express style path to RegExp utility",
"version": "0.1.9",
"version": "0.1.10",
"files": [

@@ -24,3 +24,3 @@ "index.js",

"type": "git",
"url": "https://github.com/component/path-to-regexp.git"
"url": "https://github.com/pillarjs/path-to-regexp.git"
},

@@ -27,0 +27,0 @@ "devDependencies": {

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