pax_global_header00006660000000000000000000000064140531711300014505gustar00rootroot0000000000000052 comment=9f1db2802ffbc572e6b447f66126697e33b0055e path-parse-1.0.7/000077500000000000000000000000001405317113000135565ustar00rootroot00000000000000path-parse-1.0.7/.npmignore000066400000000000000000000000341405317113000155520ustar00rootroot00000000000000.travis.yml redos.js test.jspath-parse-1.0.7/.travis.yml000066400000000000000000000001511405317113000156640ustar00rootroot00000000000000language: node_js node_js: - "0.12" - "0.11" - "0.10" - "0.10.12" - "0.8" - "0.6" - "iojs" path-parse-1.0.7/LICENSE000066400000000000000000000020701405317113000145620ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2015 Javier Blanco Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. path-parse-1.0.7/README.md000066400000000000000000000015471405317113000150440ustar00rootroot00000000000000# path-parse [![Build Status](https://travis-ci.org/jbgutierrez/path-parse.svg?branch=master)](https://travis-ci.org/jbgutierrez/path-parse) > Node.js [`path.parse(pathString)`](https://nodejs.org/api/path.html#path_path_parse_pathstring) [ponyfill](https://ponyfill.com). ## Install ``` $ npm install --save path-parse ``` ## Usage ```js var pathParse = require('path-parse'); pathParse('/home/user/dir/file.txt'); //=> { // root : "/", // dir : "/home/user/dir", // base : "file.txt", // ext : ".txt", // name : "file" // } ``` ## API See [`path.parse(pathString)`](https://nodejs.org/api/path.html#path_path_parse_pathstring) docs. ### pathParse(path) ### pathParse.posix(path) The Posix specific version. ### pathParse.win32(path) The Windows specific version. ## License MIT © [Javier Blanco](http://jbgutierrez.info) path-parse-1.0.7/index.js000066400000000000000000000035451405317113000152320ustar00rootroot00000000000000'use strict'; var isWindows = process.platform === 'win32'; // Regex to split a windows path into into [dir, root, basename, name, ext] var splitWindowsRe = /^(((?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?[\\\/]?)(?:[^\\\/]*[\\\/])*)((\.{1,2}|[^\\\/]+?|)(\.[^.\/\\]*|))[\\\/]*$/; var win32 = {}; function win32SplitPath(filename) { return splitWindowsRe.exec(filename).slice(1); } win32.parse = function(pathString) { if (typeof pathString !== 'string') { throw new TypeError( "Parameter 'pathString' must be a string, not " + typeof pathString ); } var allParts = win32SplitPath(pathString); if (!allParts || allParts.length !== 5) { throw new TypeError("Invalid path '" + pathString + "'"); } return { root: allParts[1], dir: allParts[0] === allParts[1] ? allParts[0] : allParts[0].slice(0, -1), base: allParts[2], ext: allParts[4], name: allParts[3] }; }; // Split a filename into [dir, root, basename, name, ext], unix version // 'root' is just a slash, or nothing. var splitPathRe = /^((\/?)(?:[^\/]*\/)*)((\.{1,2}|[^\/]+?|)(\.[^.\/]*|))[\/]*$/; var posix = {}; function posixSplitPath(filename) { return splitPathRe.exec(filename).slice(1); } posix.parse = function(pathString) { if (typeof pathString !== 'string') { throw new TypeError( "Parameter 'pathString' must be a string, not " + typeof pathString ); } var allParts = posixSplitPath(pathString); if (!allParts || allParts.length !== 5) { throw new TypeError("Invalid path '" + pathString + "'"); } return { root: allParts[1], dir: allParts[0].slice(0, -1), base: allParts[2], ext: allParts[4], name: allParts[3], }; }; if (isWindows) module.exports = win32.parse; else /* posix */ module.exports = posix.parse; module.exports.posix = posix.parse; module.exports.win32 = win32.parse; path-parse-1.0.7/package.json000066400000000000000000000012331405317113000160430ustar00rootroot00000000000000{ "name": "path-parse", "version": "1.0.7", "description": "Node.js path.parse() ponyfill", "main": "index.js", "scripts": { "test": "node test.js" }, "repository": { "type": "git", "url": "https://github.com/jbgutierrez/path-parse.git" }, "keywords": [ "path", "paths", "file", "dir", "parse", "built-in", "util", "utils", "core", "ponyfill", "polyfill", "shim" ], "author": "Javier Blanco ", "license": "MIT", "bugs": { "url": "https://github.com/jbgutierrez/path-parse/issues" }, "homepage": "https://github.com/jbgutierrez/path-parse#readme" } path-parse-1.0.7/redos.js000066400000000000000000000007741405317113000152400ustar00rootroot00000000000000var pathParse = require('.'); function build_attack(n) { var ret = "" for (var i = 0; i < n; i++) { ret += "/" } return ret + "◎"; } for(var i = 1; i <= 5000000; i++) { if (i % 10000 == 0) { var time = Date.now(); var attack_str = build_attack(i) pathParse.posix(attack_str); pathParse.win32(attack_str); var time_cost = Date.now() - time; console.log("attack_str.length: " + attack_str.length + ": " + time_cost+" ms") } } path-parse-1.0.7/test.js000066400000000000000000000072101405317113000150730ustar00rootroot00000000000000var assert = require('assert'); var pathParse = require('./index'); var winParseTests = [ [{ root: 'C:\\', dir: 'C:\\path\\dir', base: 'index.html', ext: '.html', name: 'index' }, 'C:\\path\\dir\\index.html'], [{ root: 'C:\\', dir: 'C:\\another_path\\DIR\\1\\2\\33', base: 'index', ext: '', name: 'index' }, 'C:\\another_path\\DIR\\1\\2\\33\\index'], [{ root: '', dir: 'another_path\\DIR with spaces\\1\\2\\33', base: 'index', ext: '', name: 'index' }, 'another_path\\DIR with spaces\\1\\2\\33\\index'], [{ root: '\\', dir: '\\foo', base: 'C:', ext: '', name: 'C:' }, '\\foo\\C:'], [{ root: '', dir: '', base: 'file', ext: '', name: 'file' }, 'file'], [{ root: '', dir: '.', base: 'file', ext: '', name: 'file' }, '.\\file'], // unc [{ root: '\\\\server\\share\\', dir: '\\\\server\\share\\', base: 'file_path', ext: '', name: 'file_path' }, '\\\\server\\share\\file_path'], [{ root: '\\\\server two\\shared folder\\', dir: '\\\\server two\\shared folder\\', base: 'file path.zip', ext: '.zip', name: 'file path' }, '\\\\server two\\shared folder\\file path.zip'], [{ root: '\\\\teela\\admin$\\', dir: '\\\\teela\\admin$\\', base: 'system32', ext: '', name: 'system32' }, '\\\\teela\\admin$\\system32'], [{ root: '\\\\?\\UNC\\', dir: '\\\\?\\UNC\\server', base: 'share', ext: '', name: 'share' }, '\\\\?\\UNC\\server\\share'] ]; var winSpecialCaseFormatTests = [ [{dir: 'some\\dir'}, 'some\\dir\\'], [{base: 'index.html'}, 'index.html'], [{}, ''] ]; var unixParseTests = [ [{ root: '/', dir: '/home/user/dir', base: 'file.txt', ext: '.txt', name: 'file' }, '/home/user/dir/file.txt'], [{ root: '/', dir: '/home/user/a dir', base: 'another File.zip', ext: '.zip', name: 'another File' }, '/home/user/a dir/another File.zip'], [{ root: '/', dir: '/home/user/a dir/', base: 'another&File.', ext: '.', name: 'another&File' }, '/home/user/a dir//another&File.'], [{ root: '/', dir: '/home/user/a$$$dir/', base: 'another File.zip', ext: '.zip', name: 'another File' }, '/home/user/a$$$dir//another File.zip'], [{ root: '', dir: 'user/dir', base: 'another File.zip', ext: '.zip', name: 'another File' }, 'user/dir/another File.zip'], [{ root: '', dir: '', base: 'file', ext: '', name: 'file' }, 'file'], [{ root: '', dir: '', base: '.\\file', ext: '', name: '.\\file' }, '.\\file'], [{ root: '', dir: '.', base: 'file', ext: '', name: 'file' }, './file'], [{ root: '', dir: '', base: 'C:\\foo', ext: '', name: 'C:\\foo' }, 'C:\\foo'] ]; var unixSpecialCaseFormatTests = [ [{dir: 'some/dir'}, 'some/dir/'], [{base: 'index.html'}, 'index.html'], [{}, ''] ]; var errors = [ {input: null, message: /Parameter 'pathString' must be a string, not/}, {input: {}, message: /Parameter 'pathString' must be a string, not object/}, {input: true, message: /Parameter 'pathString' must be a string, not boolean/}, {input: 1, message: /Parameter 'pathString' must be a string, not number/}, {input: undefined, message: /Parameter 'pathString' must be a string, not undefined/}, ]; checkParseFormat(pathParse.win32, winParseTests); checkParseFormat(pathParse.posix, unixParseTests); checkErrors(pathParse.win32); checkErrors(pathParse.posix); function checkErrors(parse) { errors.forEach(function(errorCase) { try { parse(errorCase.input); } catch(err) { assert.ok(err instanceof TypeError); assert.ok( errorCase.message.test(err.message), 'expected ' + errorCase.message + ' to match ' + err.message ); return; } assert.fail('should have thrown'); }); } function checkParseFormat(parse, testCases) { testCases.forEach(function(testCase) { assert.deepEqual(parse(testCase[1]), testCase[0]); }); }