update filters and catch erroneous URLs

main
Lee Hanken 2022-01-18 16:39:42 +00:00
parent 020d051d0f
commit 90fb16b81e
53 changed files with 4726 additions and 36 deletions

View File

@ -3,6 +3,7 @@ const turndown = require('turndown');
const { Readability } = require('@mozilla/readability');
const JSDOM = require('jsdom').JSDOM;
const common_filters = require('./url_to_markdown_common_filters');
const validURL = require('@7c/validurl');
service = new turndown();
@ -24,10 +25,10 @@ app.use(rateLimiter)
app.get('/', (req, res) => {
url = req.query.url;
res.header("Access-Control-Allow-Origin", '*');
if (url) {
if (url && validURL(url)) {
read_url(url, res);
} else {
res.send("Please specify url query parameter.");
res.status(400).send("Please specify a valid url query parameter");
}
});
@ -41,5 +42,7 @@ function read_url(url, res) {
let markdown = service.turndown(article.content);
let result = common_filters.filter(url, markdown);
res.send(result);
}).catch((error)=> {
res.status(400).send("Sorry, could not fetch and convert that URL");
});
}

39
node_modules/.package-lock.json generated vendored
View File

@ -4,6 +4,11 @@
"lockfileVersion": 2,
"requires": true,
"packages": {
"node_modules/@7c/validurl": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/@7c/validurl/-/validurl-0.0.3.tgz",
"integrity": "sha512-hmy54tf9ANyD2Iy0F6w0tF+jLwMDvpUWRD+jsSppinIINsre74IOlU79M6BdZLdcFoz9CNDVX6XofOT7O5ne8w=="
},
"node_modules/@mozilla/readability": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/@mozilla/readability/-/readability-0.3.0.tgz",
@ -407,9 +412,9 @@
}
},
"node_modules/express-rate-limit": {
"version": "6.0.5",
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-6.0.5.tgz",
"integrity": "sha512-EB1mRTrzyyPfEsQZIQFXocd8NKZoDZbEwrtbdgkc20Yed6oYg02Xfjza2HHPI/0orp54BrFeHeT92ICB9ydokw==",
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-6.1.0.tgz",
"integrity": "sha512-OWyJUDYVq/hRxGU3ufTnXDer5bRBwFiq5D35ZSZ9B2EHdjulWO4bwrbg+iIrapodDZse/35obeOj7igRHuP3Zw==",
"engines": {
"node": ">= 14.5.0"
},
@ -810,6 +815,15 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/querystring": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz",
"integrity": "sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA=",
"deprecated": "The querystring API is considered Legacy. new code should use the URLSearchParams API instead.",
"engines": {
"node": ">=0.4.x"
}
},
"node_modules/range-parser": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
@ -1015,6 +1029,20 @@
"node": ">= 0.8"
}
},
"node_modules/url": {
"version": "0.11.0",
"resolved": "https://registry.npmjs.org/url/-/url-0.11.0.tgz",
"integrity": "sha1-ODjpfPxgUh63PFJajlW/3Z4uKPE=",
"dependencies": {
"punycode": "1.3.2",
"querystring": "0.2.0"
}
},
"node_modules/url/node_modules/punycode": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.3.2.tgz",
"integrity": "sha1-llOgNvt8HuQjQvIyXM7v6jkmxI0="
},
"node_modules/utils-merge": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
@ -1023,6 +1051,11 @@
"node": ">= 0.4.0"
}
},
"node_modules/valid-url": {
"version": "1.0.9",
"resolved": "https://registry.npmjs.org/valid-url/-/valid-url-1.0.9.tgz",
"integrity": "sha1-HBRHm0DxOXp1eC8RXkCGRHQzogA="
},
"node_modules/vary": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",

30
node_modules/@7c/validurl/README.md generated vendored Normal file
View File

@ -0,0 +1,30 @@
# validURL
validating URLs is tricky job. There are tons of approaches. This is my liberal approach.
## Features
- supports any protocols (https|http|ftp|arbitrary)://
- supports ipv6 hostnames
- supports punycode urls
- tested against 1.3M URLs
## Testing
testing might take a while, since we are testing against 1.3Million URLs. Test files are only available at github clone. They will be ignored for npm package.
`npm run test`
## Install
```
npm i --save @7c/validurl
```
## Usage
```
const validURL = require('@7c/validurl')
console.log(validURL('http://localhost'))
```
All kind of bugreports are welcome

24
node_modules/@7c/validurl/package.json generated vendored Normal file
View File

@ -0,0 +1,24 @@
{
"name": "@7c/validurl",
"version": "0.0.3",
"description": "rigorous url validation",
"keywords": [
"url",
"validation"
],
"repository": {
"type": "git",
"url": "https://github.com/7c/validurl.git"
},
"main": "validURL.js",
"scripts": {
"test": "node_modules/mocha/bin/mocha tests/*.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^8.2.1",
"should": "^13.2.3"
}
}

190
node_modules/@7c/validurl/tests/validURL.js generated vendored Normal file
View File

@ -0,0 +1,190 @@
const validURL = require('./../validURL.js')
const expect = require('chai').expect
const fs = require('fs')
const chalk = require('chalk')
const readline = require('readline')
const zlib = require('zlib');
describe("validURL Function", function () {
this.timeout(30000000)
url = validURL
it("allows empty values", function () {
expect(url(null)).to.be.false;
expect(url(undefined)).to.be.false;
});
it("doesn't allow non strings", function () {
expect(url(3.14, {})).to.be.false;
expect(url(true, {})).to.be.false;
expect(url({ key: "i'm a string" }, {})).to.be.false;
});
it("different tests", function () {
expect(url("", {})).to.be.false;
expect(url(" ", {})).to.be.false;
expect(url("http://", {})).to.be.false;
expect(url("http://.", {})).to.be.false;
expect(url("http://..", {})).to.be.false;
expect(url("http://../", {})).to.be.false;
expect(url("http://?", {})).to.be.false;
expect(url("http://??", {})).to.be.false;
expect(url("http://??/", {})).to.be.false;
expect(url("http://#", {})).to.be.false;
expect(url("http://##", {})).to.be.false;
expect(url("http://##/", {})).to.be.false;
expect(url("http://foo.bar?q=Spaces should be encoded", {})).to.be.false;
expect(url("//", {})).to.be.false;
expect(url("//a", {})).to.be.false;
expect(url("///a", {})).to.be.false;
expect(url("///", {})).to.be.false;
expect(url("http:///a", {})).to.be.false;
expect(url("foo.com", {})).to.be.true;
expect(url("rdar://1234", {})).to.be.false;
expect(url("h://test", {})).to.be.true;
expect(url("http:// shouldfail.com", {})).to.be.false;
expect(url(":// should fail", {})).to.be.false;
expect(url("http://foo.bar/foo(bar)baz quux", {})).to.be.false; // must be encoded
expect(url("ftps://foo.bar/", {})).to.be.true;
expect(url("http://-error-.invalid/", {})).to.be.false;
expect(url("http://-a.b.co", {})).to.be.false;
expect(url("http://a.b-.co", {})).to.be.false;
expect(url("http://0.0.0.0", {})).to.be.true;
expect(url("http://10.1.1.0", {})).to.be.true;
expect(url("http://10.1.1.255", {})).to.be.true;
expect(url("http://224.1.1.1", {})).to.be.true;
expect(url("http://1.1.1.1.1", {})).to.be.false;
expect(url("http://123.123.123", {})).to.be.false;
expect(url("http://3628126748", {})).to.be.false;
expect(url("http://10.1.1.1", {})).to.be.true;
expect(url("http://localhost", {})).to.be.true;
expect(url("http://.www.foo.bar/", {})).to.be.false;
expect(url("http://www.foo.bar./", {})).to.be.true;
expect(url("http://.www.foo.bar./", {})).to.be.false;
expect(url('https://rdap.nic.xn--1ck2e1b/domain/test.xn--1ck2e1b')).to.be.true
expect(url('https//nedomain7812423.com/echo')).to.be.false
});
/*
it("allows valid urls", function() {
expect(url("http://foo.com", {})).to.be.true;
expect(url("http://foo.com/", {})).to.be.true;
expect(url("http://foo.com/blah_blah", {})).to.be.true;
expect(url("http://foo.com/blah_blah/", {})).to.be.true;
expect(url("http://foo.com/blah_blah_(wikipedia)", {})).to.be.true;
expect(url("http://foo.com/blah_blah_(wikipedia)_(again)", {})).to.be.true;
expect(url("http://foo.com?query=bar", {})).to.be.true;
expect(url("http://foo.com#fragment=bar", {})).to.be.true;
expect(url("http://www.example.com/wpstyle/?p=364", {})).to.be.true;
expect(url("https://www.example.com/foo/?bar=baz&inga=42&quux", {})).to.be.true;
expect(url("https://www.example.com/foo/#bar=baz&inga=42&quux", {})).to.be.true;
expect(url("http://✪df.ws/123", {})).to.be.true;
expect(url("http://userid:password@example.com:8080", {})).to.be.true;
expect(url("http://userid:password@example.com:8080/", {})).to.be.true;
expect(url("http://userid@example.com", {})).to.be.true;
expect(url("http://userid@example.com/", {})).to.be.true;
expect(url("http://userid@example.com:8080", {})).to.be.true;
expect(url("http://userid@example.com:8080/", {})).to.be.true;
expect(url("http://userid:password@example.com", {})).to.be.true;
expect(url("http://userid:password@example.com/", {})).to.be.true;
expect(url("http://142.42.1.1/", {})).to.be.true;
expect(url("http://142.42.1.1:8080/", {})).to.be.true;
expect(url("http://➡.ws/䨹", {})).to.be.true;
expect(url("http://⌘.ws", {})).to.be.true;
expect(url("http://⌘.ws/", {})).to.be.true;
expect(url("http://foo.com/blah_(wikipedia)#cite-1", {})).to.be.true;
expect(url("http://foo.com/blah_(wikipedia)_blah#cite-1", {})).to.be.true;
expect(url("http://foo.com/unicode_(✪)_in_parens", {})).to.be.true;
expect(url("http://foo.com/(something)?after=parens", {})).to.be.true;
expect(url("http://☺.damowmow.com/", {})).to.be.true;
expect(url("http://code.google.com/events/#&product=browser", {})).to.be.true;
expect(url("http://j.mp", {})).to.be.true;
expect(url("http://foo.bar/?q=Test%20URL-encoded%20stuff", {})).to.be.true;
expect(url("http://مثال.إختبار", {})).to.be.true;
expect(url("http://例子.测试", {})).to.be.true;
expect(url("http://उदाहरण.परीक्षा", {})).to.be.true;
expect(url("http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com", {})).to.be.true;
expect(url("http://1337.net", {})).to.be.true;
expect(url("http://a.b-c.de", {})).to.be.true;
expect(url("http://223.255.255.254", {})).to.be.true;
expect(url("http://a.b--c.de/", {})).to.be.true;
});
// it("allows local url and private networks if option is set", function() {
// expect(url("http://10.1.1.1")).to.be.true;
// expect(url("http://172.16.1.123")).to.be.true;
// expect(url("http://192.168.1.123")).to.be.true;
// expect(url("http://localhost/foo")).to.be.true;
// expect(url("http://localhost:4711/foo")).to.be.true;
// // Issue #95
// expect(url("http://servername01:8153/go/cctray.xml")).to.be.false;
// expect(url("http://nicklas:password@localhost:4711/foo")).to.be.false;
// });
it("not allow data urls", function () {
//Examples from https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
expect(url("data:,Hello%2C%20World!")).to.be.false;
expect(url("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D")).to.be.false;
expect(url("data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E")).to.be.false;
});
it("fails data urls without the option", function () {
//Examples from https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
expect(url("data:,Hello%2C%20World!")).to.be.false;
expect(url("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D")).to.be.false;
expect(url("data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E")).to.be.false;
})
it("custom schemes", function() {
var options = {schemes: ['ftp', 'jdbc']};
expect(url("ftp://foo.bar.com", options)).to.be.true;
expect(url("jdbc://foo.bar.com", options)).to.be.false;
expect(url("http://foo.bar.com", options)).to.be.true;
})
*/
it("tests from data.url.invalid.txt file", async function () {
var rs = fs.createReadStream(__dirname + '/data.url.invalid.txt')
rs.on('error', function (err) {
console.log(err)
rs.end(err);
});
const rl = readline.createInterface({
input: rs,
crlfDelay: Infinity
})
for await (var u of rl) {
if (u.trim().length === 0) continue
u = u.replace(/\"/g, '')
expect(url(u)).to.be.false
}
})
it("tests from data.url.valid.txt file", async function () {
var rs = fs.createReadStream(__dirname + '/data.url.valid.txt.gz').pipe(zlib.createGunzip())
rs.on('error', function (err) {
console.log(err)
rs.end(err);
});
const rl = readline.createInterface({
input: rs,
crlfDelay: Infinity
})
for await (var u of rl) {
if (u.trim().length === 0) continue
u = u.replace(/\"/g, '')
expect(url(u),'url:"'+u+'"').to.be.true
}
})
});

67
node_modules/@7c/validurl/validURL.js generated vendored Normal file
View File

@ -0,0 +1,67 @@
const net = require('net')
const querystring = require('querystring')
function validHostname(domainName) {
var domainNameRegex = /^(?:[a-z0-9](?:[a-z0-9_\-]{0,61}[a-z0-9])?\.){0,126}(?:[a-z0-9](?:[a-z0-9\-]{0,61}[a-z0-9]))\.?$/i
// is an ip host
if (net.isIPv4(domainName) || net.isIPv6(domainName.replace(/[\[\]]/g,''))) return true
// remove last '.'
domainName=domainName.replace(/\.$/,'')
if (domainName.length < 2) return false
if (domainName.length > 255) return false
if (domainName.search(/\./)<0 && domainName.search(/^[0-9]+$/)==0) {
// using numbers without . in body
return false
}
return domainNameRegex.test(domainName)
}
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}
module.exports = (host) => {
if (!host) return false
if (typeof host!=='string') return false
// we accept any protocol
// we normalize hosts without protocol
// if (host.search(/^[a-z]+:\/\//i)!==0) {
if (host.search(/^[^/]+\/\//)!==0) {
// no protocol
if (host.search(/^\//)<0) {
if (host.search(/\:80/)>0) host='http://'+host;
else if (host.search(/\:443/)>0) host='https://'+host;
else host='http://'+host;
}
}
try {
var U = new URL(host)
// console.log(U)
if (host.search(escapeRegExp(U.search.toString()))<0) {
// search was not escaped properly
return false
}
if (host.search(escapeRegExp(U.pathname.toString()))<0) {
// pathname must be encoded
return false
}
if (host.search(escapeRegExp(U.hostname))<0) {
// new URL('http://123.123.123') returns .hostname='123.123.0.123' // strange
return false
}
// console.log(U)
querystring.encode(U.search)
if (!validHostname(U.hostname)) return false
return true
}catch(err) {
// console.log(err)
// ignore
}
return false
}

View File

@ -6,6 +6,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [6.1.0](https://github.com/nfriedly/express-rate-limit/releases/tag/v6.1.0)
### Added
- Added a named export `rateLimit` in case the default import does not work.
### Fixed
- Added a named export `default`, so Typescript CommonJS developers can
default-import the library (`import rateLimit from 'express-rate-limit'`).
## [6.0.5](https://github.com/nfriedly/express-rate-limit/releases/tag/v6.0.5)
### Fixed

View File

@ -24,7 +24,8 @@ var __toCommonJS = /* @__PURE__ */ ((cache) => {
// source/index.ts
var source_exports = {};
__export(source_exports, {
default: () => source_default
default: () => lib_default,
rateLimit: () => lib_default
});
// source/memory-store.ts
@ -219,8 +220,5 @@ var rateLimit = (passedOptions) => {
return middleware;
};
var lib_default = rateLimit;
// source/index.ts
var source_default = lib_default;
module.exports = __toCommonJS(source_exports);
module.exports = rateLimit;
module.exports = rateLimit; module.exports.default = rateLimit; module.exports.rateLimit = rateLimit;

View File

@ -1,4 +1,4 @@
// Generated by dts-bundle-generator v6.3.0
// Generated by dts-bundle-generator v6.4.0
import { NextFunction, Request, RequestHandler, Response } from 'express';
@ -240,9 +240,22 @@ export interface RateLimitInfo {
readonly remaining: number;
readonly resetTime: Date | undefined;
}
declare const rateLimit: (passedOptions?: (Omit<Partial<Options>, "store"> & {
/**
*
* Create an instance of IP rate-limiting middleware for Express.
*
* @param passedOptions {Options} - Options to configure the rate limiter
*
* @returns {RateLimitRequestHandler} - The middleware that rate-limits clients based on your configuration
*
* @public
*/
export declare const rateLimit: (passedOptions?: (Omit<Partial<Options>, "store"> & {
store?: LegacyStore | Store | undefined;
}) | undefined) => RateLimitRequestHandler;
export default rateLimit;
export {
rateLimit as default,
};
export {};

View File

@ -190,9 +190,7 @@ var rateLimit = (passedOptions) => {
return middleware;
};
var lib_default = rateLimit;
// source/index.ts
var source_default = lib_default;
export {
source_default as default
lib_default as default,
lib_default as rateLimit
};

View File

@ -1,6 +1,6 @@
{
"name": "express-rate-limit",
"version": "6.0.5",
"version": "6.1.0",
"description": "Basic IP rate-limiting middleware for Express. Use to limit repeated requests to public APIs and/or endpoints such as password reset.",
"author": {
"name": "Nathan Friedly",
@ -50,7 +50,7 @@
},
"scripts": {
"clean": "del-cli dist/ coverage/ *.log *.tmp *.bak *.tgz",
"build:cjs": "esbuild --bundle --format=cjs --outfile=dist/index.cjs --footer:js=\"module.exports = rateLimit;\" source/index.ts",
"build:cjs": "esbuild --bundle --format=cjs --outfile=dist/index.cjs --footer:js=\"module.exports = rateLimit; module.exports.default = rateLimit; module.exports.rateLimit = rateLimit;\" source/index.ts",
"build:esm": "esbuild --bundle --format=esm --outfile=dist/index.mjs source/index.ts",
"build:types": "dts-bundle-generator --out-file=dist/index.d.ts source/index.ts",
"compile": "run-s clean build:*",
@ -61,7 +61,7 @@
"autofix:rest": "prettier --ignore-path .gitignore --ignore-unknown --write .",
"autofix": "run-s autofix:*",
"test:lib": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
"test:ext": "npm pack && cd test/external/ && bash run-all-tests",
"test:ext": "cd test/external/ && bash run-all-tests",
"test": "run-s lint test:*",
"pre-commit": "lint-staged",
"prepare": "run-s compile && husky install config/husky"
@ -73,18 +73,18 @@
"@jest/globals": "^27.4.6",
"@types/express": "^4.17.13",
"@types/jest": "^27.4.0",
"@types/node": "^16.11.17",
"@types/node": "^16.11.19",
"@types/supertest": "^2.0.11",
"cross-env": "^7.0.3",
"del-cli": "^4.0.1",
"dts-bundle-generator": "^6.3.0",
"esbuild": "^0.14.10",
"dts-bundle-generator": "^6.4.0",
"esbuild": "^0.14.11",
"express": "^4.17.1",
"husky": "^7.0.4",
"jest": "^27.4.7",
"lint-staged": "^12.1.5",
"lint-staged": "^12.1.7",
"npm-run-all": "^4.1.5",
"supertest": "^6.1.6",
"supertest": "^6.2.1",
"ts-jest": "^27.1.1",
"ts-node": "^10.4.0",
"typescript": "^4.5.2",

BIN
node_modules/querystring/.History.md.un~ generated vendored Normal file

Binary file not shown.

BIN
node_modules/querystring/.Readme.md.un~ generated vendored Normal file

Binary file not shown.

BIN
node_modules/querystring/.package.json.un~ generated vendored Normal file

Binary file not shown.

4
node_modules/querystring/.travis.yml generated vendored Normal file
View File

@ -0,0 +1,4 @@
language: node_js
node_js:
- 0.6
- 0.8

20
node_modules/querystring/History.md generated vendored Normal file
View File

@ -0,0 +1,20 @@
# 0.2.0 / 2013-02-21
- Refactor into function per-module idiomatic style.
- Improved test coverage.
# 0.1.0 / 2011-12-13
- Minor project reorganization
# 0.0.3 / 2011-04-16
- Support for AMD module loaders
# 0.0.2 / 2011-04-16
- Ported unit tests
- Removed functionality that depended on Buffers
# 0.0.1 / 2011-04-15
- Initial release

19
node_modules/querystring/License.md generated vendored Normal file
View File

@ -0,0 +1,19 @@
Copyright 2012 Irakli Gozalishvili. All rights reserved.
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.

15
node_modules/querystring/Readme.md generated vendored Normal file
View File

@ -0,0 +1,15 @@
# querystring
[![Build Status](https://secure.travis-ci.org/Gozala/querystring.png)](http://travis-ci.org/Gozala/querystring)
[![Browser support](http://ci.testling.com/Gozala/querystring.png)](http://ci.testling.com/Gozala/querystring)
Node's querystring module for all engines.
## Install ##
npm install querystring

80
node_modules/querystring/decode.js generated vendored Normal file
View File

@ -0,0 +1,80 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// 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.
'use strict';
// If obj.hasOwnProperty has been overridden, then calling
// obj.hasOwnProperty(prop) will break.
// See: https://github.com/joyent/node/issues/1707
function hasOwnProperty(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
}
module.exports = function(qs, sep, eq, options) {
sep = sep || '&';
eq = eq || '=';
var obj = {};
if (typeof qs !== 'string' || qs.length === 0) {
return obj;
}
var regexp = /\+/g;
qs = qs.split(sep);
var maxKeys = 1000;
if (options && typeof options.maxKeys === 'number') {
maxKeys = options.maxKeys;
}
var len = qs.length;
// maxKeys <= 0 means that we should not limit keys count
if (maxKeys > 0 && len > maxKeys) {
len = maxKeys;
}
for (var i = 0; i < len; ++i) {
var x = qs[i].replace(regexp, '%20'),
idx = x.indexOf(eq),
kstr, vstr, k, v;
if (idx >= 0) {
kstr = x.substr(0, idx);
vstr = x.substr(idx + 1);
} else {
kstr = x;
vstr = '';
}
k = decodeURIComponent(kstr);
v = decodeURIComponent(vstr);
if (!hasOwnProperty(obj, k)) {
obj[k] = v;
} else if (Array.isArray(obj[k])) {
obj[k].push(v);
} else {
obj[k] = [obj[k], v];
}
}
return obj;
};

64
node_modules/querystring/encode.js generated vendored Normal file
View File

@ -0,0 +1,64 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// 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.
'use strict';
var stringifyPrimitive = function(v) {
switch (typeof v) {
case 'string':
return v;
case 'boolean':
return v ? 'true' : 'false';
case 'number':
return isFinite(v) ? v : '';
default:
return '';
}
};
module.exports = function(obj, sep, eq, name) {
sep = sep || '&';
eq = eq || '=';
if (obj === null) {
obj = undefined;
}
if (typeof obj === 'object') {
return Object.keys(obj).map(function(k) {
var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
if (Array.isArray(obj[k])) {
return obj[k].map(function(v) {
return ks + encodeURIComponent(stringifyPrimitive(v));
}).join(sep);
} else {
return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
}
}).join(sep);
}
if (!name) return '';
return encodeURIComponent(stringifyPrimitive(name)) + eq +
encodeURIComponent(stringifyPrimitive(obj));
};

4
node_modules/querystring/index.js generated vendored Normal file
View File

@ -0,0 +1,4 @@
'use strict';
exports.decode = exports.parse = require('./decode');
exports.encode = exports.stringify = require('./encode');

65
node_modules/querystring/package.json generated vendored Normal file
View File

@ -0,0 +1,65 @@
{
"name": "querystring",
"id": "querystring",
"version": "0.2.0",
"description": "Node's querystring module for all engines.",
"keywords": [ "commonjs", "query", "querystring" ],
"author": "Irakli Gozalishvili <rfobic@gmail.com>",
"repository": {
"type": "git",
"url": "git://github.com/Gozala/querystring.git",
"web": "https://github.com/Gozala/querystring"
},
"bugs": {
"url": "http://github.com/Gozala/querystring/issues/"
},
"devDependencies": {
"test": "~0.x.0",
"phantomify": "~0.x.0",
"retape": "~0.x.0",
"tape": "~0.1.5"
},
"engines": {
"node": ">=0.4.x"
},
"scripts": {
"test": "npm run test-node && npm run test-browser && npm run test-tap",
"test-browser": "node ./node_modules/phantomify/bin/cmd.js ./test/common-index.js",
"test-node": "node ./test/common-index.js",
"test-tap": "node ./test/tap-index.js"
},
"testling": {
"files": "test/tap-index.js",
"browsers": {
"iexplore": [
9,
10
],
"chrome": [
16,
20,
25,
"canary"
],
"firefox": [
10,
15,
16,
17,
18,
"nightly"
],
"safari": [
5,
6
],
"opera": [
12
]
}
},
"licenses": [{
"type" : "MIT",
"url" : "https://github.com/Gozala/enchain/License.md"
}]
}

BIN
node_modules/querystring/test/.index.js.un~ generated vendored Normal file

Binary file not shown.

3
node_modules/querystring/test/common-index.js generated vendored Normal file
View File

@ -0,0 +1,3 @@
"use strict";
require("test").run(require("./index"))

210
node_modules/querystring/test/index.js generated vendored Normal file
View File

@ -0,0 +1,210 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// 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.
"use strict";
// test using assert
var qs = require('../');
// folding block, commented to pass gjslint
// {{{
// [ wonkyQS, canonicalQS, obj ]
var qsTestCases = [
['foo=918854443121279438895193',
'foo=918854443121279438895193',
{'foo': '918854443121279438895193'}],
['foo=bar', 'foo=bar', {'foo': 'bar'}],
['foo=bar&foo=quux', 'foo=bar&foo=quux', {'foo': ['bar', 'quux']}],
['foo=1&bar=2', 'foo=1&bar=2', {'foo': '1', 'bar': '2'}],
['my+weird+field=q1%212%22%27w%245%267%2Fz8%29%3F',
'my%20weird%20field=q1!2%22\'w%245%267%2Fz8)%3F',
{'my weird field': 'q1!2"\'w$5&7/z8)?' }],
['foo%3Dbaz=bar', 'foo%3Dbaz=bar', {'foo=baz': 'bar'}],
['foo=baz=bar', 'foo=baz%3Dbar', {'foo': 'baz=bar'}],
['str=foo&arr=1&arr=2&arr=3&somenull=&undef=',
'str=foo&arr=1&arr=2&arr=3&somenull=&undef=',
{ 'str': 'foo',
'arr': ['1', '2', '3'],
'somenull': '',
'undef': ''}],
[' foo = bar ', '%20foo%20=%20bar%20', {' foo ': ' bar '}],
// disable test that fails ['foo=%zx', 'foo=%25zx', {'foo': '%zx'}],
['foo=%EF%BF%BD', 'foo=%EF%BF%BD', {'foo': '\ufffd' }],
// See: https://github.com/joyent/node/issues/1707
['hasOwnProperty=x&toString=foo&valueOf=bar&__defineGetter__=baz',
'hasOwnProperty=x&toString=foo&valueOf=bar&__defineGetter__=baz',
{ hasOwnProperty: 'x',
toString: 'foo',
valueOf: 'bar',
__defineGetter__: 'baz' }],
// See: https://github.com/joyent/node/issues/3058
['foo&bar=baz', 'foo=&bar=baz', { foo: '', bar: 'baz' }]
];
// [ wonkyQS, canonicalQS, obj ]
var qsColonTestCases = [
['foo:bar', 'foo:bar', {'foo': 'bar'}],
['foo:bar;foo:quux', 'foo:bar;foo:quux', {'foo': ['bar', 'quux']}],
['foo:1&bar:2;baz:quux',
'foo:1%26bar%3A2;baz:quux',
{'foo': '1&bar:2', 'baz': 'quux'}],
['foo%3Abaz:bar', 'foo%3Abaz:bar', {'foo:baz': 'bar'}],
['foo:baz:bar', 'foo:baz%3Abar', {'foo': 'baz:bar'}]
];
// [wonkyObj, qs, canonicalObj]
var extendedFunction = function() {};
extendedFunction.prototype = {a: 'b'};
var qsWeirdObjects = [
[{regexp: /./g}, 'regexp=', {'regexp': ''}],
[{regexp: new RegExp('.', 'g')}, 'regexp=', {'regexp': ''}],
[{fn: function() {}}, 'fn=', {'fn': ''}],
[{fn: new Function('')}, 'fn=', {'fn': ''}],
[{math: Math}, 'math=', {'math': ''}],
[{e: extendedFunction}, 'e=', {'e': ''}],
[{d: new Date()}, 'd=', {'d': ''}],
[{d: Date}, 'd=', {'d': ''}],
[{f: new Boolean(false), t: new Boolean(true)}, 'f=&t=', {'f': '', 't': ''}],
[{f: false, t: true}, 'f=false&t=true', {'f': 'false', 't': 'true'}],
[{n: null}, 'n=', {'n': ''}],
[{nan: NaN}, 'nan=', {'nan': ''}],
[{inf: Infinity}, 'inf=', {'inf': ''}]
];
// }}}
var qsNoMungeTestCases = [
['', {}],
['foo=bar&foo=baz', {'foo': ['bar', 'baz']}],
['blah=burp', {'blah': 'burp'}],
['gragh=1&gragh=3&goo=2', {'gragh': ['1', '3'], 'goo': '2'}],
['frappucino=muffin&goat%5B%5D=scone&pond=moose',
{'frappucino': 'muffin', 'goat[]': 'scone', 'pond': 'moose'}],
['trololol=yes&lololo=no', {'trololol': 'yes', 'lololo': 'no'}]
];
exports['test basic'] = function(assert) {
assert.strictEqual('918854443121279438895193',
qs.parse('id=918854443121279438895193').id,
'prase id=918854443121279438895193');
};
exports['test that the canonical qs is parsed properly'] = function(assert) {
qsTestCases.forEach(function(testCase) {
assert.deepEqual(testCase[2], qs.parse(testCase[0]),
'parse ' + testCase[0]);
});
};
exports['test that the colon test cases can do the same'] = function(assert) {
qsColonTestCases.forEach(function(testCase) {
assert.deepEqual(testCase[2], qs.parse(testCase[0], ';', ':'),
'parse ' + testCase[0] + ' -> ; :');
});
};
exports['test the weird objects, that they get parsed properly'] = function(assert) {
qsWeirdObjects.forEach(function(testCase) {
assert.deepEqual(testCase[2], qs.parse(testCase[1]),
'parse ' + testCase[1]);
});
};
exports['test non munge test cases'] = function(assert) {
qsNoMungeTestCases.forEach(function(testCase) {
assert.deepEqual(testCase[0], qs.stringify(testCase[1], '&', '=', false),
'stringify ' + JSON.stringify(testCase[1]) + ' -> & =');
});
};
exports['test the nested qs-in-qs case'] = function(assert) {
var f = qs.parse('a=b&q=x%3Dy%26y%3Dz');
f.q = qs.parse(f.q);
assert.deepEqual(f, { a: 'b', q: { x: 'y', y: 'z' } },
'parse a=b&q=x%3Dy%26y%3Dz');
};
exports['test nested in colon'] = function(assert) {
var f = qs.parse('a:b;q:x%3Ay%3By%3Az', ';', ':');
f.q = qs.parse(f.q, ';', ':');
assert.deepEqual(f, { a: 'b', q: { x: 'y', y: 'z' } },
'parse a:b;q:x%3Ay%3By%3Az -> ; :');
};
exports['test stringifying'] = function(assert) {
qsTestCases.forEach(function(testCase) {
assert.equal(testCase[1], qs.stringify(testCase[2]),
'stringify ' + JSON.stringify(testCase[2]));
});
qsColonTestCases.forEach(function(testCase) {
assert.equal(testCase[1], qs.stringify(testCase[2], ';', ':'),
'stringify ' + JSON.stringify(testCase[2]) + ' -> ; :');
});
qsWeirdObjects.forEach(function(testCase) {
assert.equal(testCase[1], qs.stringify(testCase[0]),
'stringify ' + JSON.stringify(testCase[0]));
});
};
exports['test stringifying nested'] = function(assert) {
var f = qs.stringify({
a: 'b',
q: qs.stringify({
x: 'y',
y: 'z'
})
});
assert.equal(f, 'a=b&q=x%3Dy%26y%3Dz',
JSON.stringify({
a: 'b',
'qs.stringify -> q': {
x: 'y',
y: 'z'
}
}));
var threw = false;
try { qs.parse(undefined); } catch(error) { threw = true; }
assert.ok(!threw, "does not throws on undefined");
};
exports['test nested in colon'] = function(assert) {
var f = qs.stringify({
a: 'b',
q: qs.stringify({
x: 'y',
y: 'z'
}, ';', ':')
}, ';', ':');
assert.equal(f, 'a:b;q:x%3Ay%3By%3Az',
'stringify ' + JSON.stringify({
a: 'b',
'qs.stringify -> q': {
x: 'y',
y: 'z'
}
}) + ' -> ; : ');
assert.deepEqual({}, qs.parse(), 'parse undefined');
};

3
node_modules/querystring/test/tap-index.js generated vendored Normal file
View File

@ -0,0 +1,3 @@
"use strict";
require("retape")(require("./index"))

1
node_modules/url/.npmignore generated vendored Normal file
View File

@ -0,0 +1 @@
test-url.js

7
node_modules/url/.travis.yml generated vendored Normal file
View File

@ -0,0 +1,7 @@
language: node_js
node_js:
- "0.10"
env:
global:
- secure: OgPRLCzHFh5WbjHEKlghHFW1oOreSF2JVUr3CMaFDi03ngTS2WONSw8mRn8SA6FTldiGGBx1n8orDzUw6cdkB7+tkU3G5B0M0V3vl823NaUFKgxsCM3UGDYfJb3yfAG5cj72rVZoX/ABd1fVuG4vBIlDLxsSlKQFMzUCFoyttr8=
- secure: AiZP8GHbyx83ZBhOvOxxtpNcgNHoP+vo5G1a1OYU78EHCgHg8NRyHKyCdrBnPvw6mV2BI/8frZaXAEicsHMtHMofBYn7nibNlaajBPI8AkHtYfNSc+zO+71Kwv7VOTOKKnkMEIkqhHlc6njFoH3QaBNHsgNlzzplPxaIt8vdUVk=

16
node_modules/url/.zuul.yml generated vendored Normal file
View File

@ -0,0 +1,16 @@
ui: mocha-tdd
browsers:
- name: chrome
version: latest
- name: firefox
version: 24..latest
- name: safari
version: latest
- name: ie
version: 9..latest
- name: iphone
version: oldest..latest
- name: ipad
version: oldest..latest
- name: android
version: oldest..latest

21
node_modules/url/LICENSE generated vendored Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright Joyent, Inc. and other Node contributors.
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.

108
node_modules/url/README.md generated vendored Normal file
View File

@ -0,0 +1,108 @@
# node-url
[![Build Status](https://travis-ci.org/defunctzombie/node-url.svg?branch=master)](https://travis-ci.org/defunctzombie/node-url)
This module has utilities for URL resolution and parsing meant to have feature parity with node.js core [url](http://nodejs.org/api/url.html) module.
```js
var url = require('url');
```
## api
Parsed URL objects have some or all of the following fields, depending on
whether or not they exist in the URL string. Any parts that are not in the URL
string will not be in the parsed object. Examples are shown for the URL
`'http://user:pass@host.com:8080/p/a/t/h?query=string#hash'`
* `href`: The full URL that was originally parsed. Both the protocol and host are lowercased.
Example: `'http://user:pass@host.com:8080/p/a/t/h?query=string#hash'`
* `protocol`: The request protocol, lowercased.
Example: `'http:'`
* `host`: The full lowercased host portion of the URL, including port
information.
Example: `'host.com:8080'`
* `auth`: The authentication information portion of a URL.
Example: `'user:pass'`
* `hostname`: Just the lowercased hostname portion of the host.
Example: `'host.com'`
* `port`: The port number portion of the host.
Example: `'8080'`
* `pathname`: The path section of the URL, that comes after the host and
before the query, including the initial slash if present.
Example: `'/p/a/t/h'`
* `search`: The 'query string' portion of the URL, including the leading
question mark.
Example: `'?query=string'`
* `path`: Concatenation of `pathname` and `search`.
Example: `'/p/a/t/h?query=string'`
* `query`: Either the 'params' portion of the query string, or a
querystring-parsed object.
Example: `'query=string'` or `{'query':'string'}`
* `hash`: The 'fragment' portion of the URL including the pound-sign.
Example: `'#hash'`
The following methods are provided by the URL module:
### url.parse(urlStr, [parseQueryString], [slashesDenoteHost])
Take a URL string, and return an object.
Pass `true` as the second argument to also parse
the query string using the `querystring` module.
Defaults to `false`.
Pass `true` as the third argument to treat `//foo/bar` as
`{ host: 'foo', pathname: '/bar' }` rather than
`{ pathname: '//foo/bar' }`. Defaults to `false`.
### url.format(urlObj)
Take a parsed URL object, and return a formatted URL string.
* `href` will be ignored.
* `protocol` is treated the same with or without the trailing `:` (colon).
* The protocols `http`, `https`, `ftp`, `gopher`, `file` will be
postfixed with `://` (colon-slash-slash).
* All other protocols `mailto`, `xmpp`, `aim`, `sftp`, `foo`, etc will
be postfixed with `:` (colon)
* `auth` will be used if present.
* `hostname` will only be used if `host` is absent.
* `port` will only be used if `host` is absent.
* `host` will be used in place of `hostname` and `port`
* `pathname` is treated the same with or without the leading `/` (slash)
* `search` will be used in place of `query`
* `query` (object; see `querystring`) will only be used if `search` is absent.
* `search` is treated the same with or without the leading `?` (question mark)
* `hash` is treated the same with or without the leading `#` (pound sign, anchor)
### url.resolve(from, to)
Take a base URL, and a href URL, and resolve them as a browser would for
an anchor tag. Examples:
url.resolve('/one/two/three', 'four') // '/one/two/four'
url.resolve('http://example.com/', '/one') // 'http://example.com/one'
url.resolve('http://example.com/one', '/two') // 'http://example.com/two'

20
node_modules/url/node_modules/punycode/LICENSE-MIT.txt generated vendored Normal file
View File

@ -0,0 +1,20 @@
Copyright Mathias Bynens <https://mathiasbynens.be/>
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.

176
node_modules/url/node_modules/punycode/README.md generated vendored Normal file
View File

@ -0,0 +1,176 @@
# Punycode.js [![Build status](https://travis-ci.org/bestiejs/punycode.js.svg?branch=master)](https://travis-ci.org/bestiejs/punycode.js) [![Code coverage status](http://img.shields.io/coveralls/bestiejs/punycode.js/master.svg)](https://coveralls.io/r/bestiejs/punycode.js) [![Dependency status](https://gemnasium.com/bestiejs/punycode.js.svg)](https://gemnasium.com/bestiejs/punycode.js)
A robust Punycode converter that fully complies to [RFC 3492](http://tools.ietf.org/html/rfc3492) and [RFC 5891](http://tools.ietf.org/html/rfc5891), and works on nearly all JavaScript platforms.
This JavaScript library is the result of comparing, optimizing and documenting different open-source implementations of the Punycode algorithm:
* [The C example code from RFC 3492](http://tools.ietf.org/html/rfc3492#appendix-C)
* [`punycode.c` by _Markus W. Scherer_ (IBM)](http://opensource.apple.com/source/ICU/ICU-400.42/icuSources/common/punycode.c)
* [`punycode.c` by _Ben Noordhuis_](https://github.com/bnoordhuis/punycode/blob/master/punycode.c)
* [JavaScript implementation by _some_](http://stackoverflow.com/questions/183485/can-anyone-recommend-a-good-free-javascript-for-punycode-to-unicode-conversion/301287#301287)
* [`punycode.js` by _Ben Noordhuis_](https://github.com/joyent/node/blob/426298c8c1c0d5b5224ac3658c41e7c2a3fe9377/lib/punycode.js) (note: [not fully compliant](https://github.com/joyent/node/issues/2072))
This project is [bundled](https://github.com/joyent/node/blob/master/lib/punycode.js) with [Node.js v0.6.2+](https://github.com/joyent/node/compare/975f1930b1...61e796decc).
## Installation
Via [npm](http://npmjs.org/) (only required for Node.js releases older than v0.6.2):
```bash
npm install punycode
```
Via [Bower](http://bower.io/):
```bash
bower install punycode
```
Via [Component](https://github.com/component/component):
```bash
component install bestiejs/punycode.js
```
In a browser:
```html
<script src="punycode.js"></script>
```
In [Narwhal](http://narwhaljs.org/), [Node.js](http://nodejs.org/), and [RingoJS](http://ringojs.org/):
```js
var punycode = require('punycode');
```
In [Rhino](http://www.mozilla.org/rhino/):
```js
load('punycode.js');
```
Using an AMD loader like [RequireJS](http://requirejs.org/):
```js
require(
{
'paths': {
'punycode': 'path/to/punycode'
}
},
['punycode'],
function(punycode) {
console.log(punycode);
}
);
```
## API
### `punycode.decode(string)`
Converts a Punycode string of ASCII symbols to a string of Unicode symbols.
```js
// decode domain name parts
punycode.decode('maana-pta'); // 'mañana'
punycode.decode('--dqo34k'); // '☃-⌘'
```
### `punycode.encode(string)`
Converts a string of Unicode symbols to a Punycode string of ASCII symbols.
```js
// encode domain name parts
punycode.encode('mañana'); // 'maana-pta'
punycode.encode('☃-⌘'); // '--dqo34k'
```
### `punycode.toUnicode(input)`
Converts a Punycode string representing a domain name or an email address to Unicode. Only the Punycoded parts of the input will be converted, i.e. it doesnt matter if you call it on a string that has already been converted to Unicode.
```js
// decode domain names
punycode.toUnicode('xn--maana-pta.com');
// → 'mañana.com'
punycode.toUnicode('xn----dqo34k.com');
// → '☃-⌘.com'
// decode email addresses
punycode.toUnicode('джумла@xn--p-8sbkgc5ag7bhce.xn--ba-lmcq');
// → 'джумла@джpумлатест.bрфa'
```
### `punycode.toASCII(input)`
Converts a Unicode string representing a domain name or an email address to Punycode. Only the non-ASCII parts of the input will be converted, i.e. it doesnt matter if you call it with a domain that's already in ASCII.
```js
// encode domain names
punycode.toASCII('mañana.com');
// → 'xn--maana-pta.com'
punycode.toASCII('☃-⌘.com');
// → 'xn----dqo34k.com'
// encode email addresses
punycode.toASCII('джумла@джpумлатест.bрфa');
// → 'джумла@xn--p-8sbkgc5ag7bhce.xn--ba-lmcq'
```
### `punycode.ucs2`
#### `punycode.ucs2.decode(string)`
Creates an array containing the numeric code point values of each Unicode symbol in the string. While [JavaScript uses UCS-2 internally](https://mathiasbynens.be/notes/javascript-encoding), this function will convert a pair of surrogate halves (each of which UCS-2 exposes as separate characters) into a single code point, matching UTF-16.
```js
punycode.ucs2.decode('abc');
// → [0x61, 0x62, 0x63]
// surrogate pair for U+1D306 TETRAGRAM FOR CENTRE:
punycode.ucs2.decode('\uD834\uDF06');
// → [0x1D306]
```
#### `punycode.ucs2.encode(codePoints)`
Creates a string based on an array of numeric code point values.
```js
punycode.ucs2.encode([0x61, 0x62, 0x63]);
// → 'abc'
punycode.ucs2.encode([0x1D306]);
// → '\uD834\uDF06'
```
### `punycode.version`
A string representing the current Punycode.js version number.
## Unit tests & code coverage
After cloning this repository, run `npm install --dev` to install the dependencies needed for Punycode.js development and testing. You may want to install Istanbul _globally_ using `npm install istanbul -g`.
Once thats done, you can run the unit tests in Node using `npm test` or `node tests/tests.js`. To run the tests in Rhino, Ringo, Narwhal, PhantomJS, and web browsers as well, use `grunt test`.
To generate the code coverage report, use `grunt cover`.
Feel free to fork if you see possible improvements!
## Author
| [![twitter/mathias](https://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](https://twitter.com/mathias "Follow @mathias on Twitter") |
|---|
| [Mathias Bynens](https://mathiasbynens.be/) |
## Contributors
| [![twitter/jdalton](https://gravatar.com/avatar/299a3d891ff1920b69c364d061007043?s=70)](https://twitter.com/jdalton "Follow @jdalton on Twitter") |
|---|
| [John-David Dalton](http://allyoucanleet.com/) |
## License
Punycode.js is available under the [MIT](https://mths.be/mit) license.

53
node_modules/url/node_modules/punycode/package.json generated vendored Normal file
View File

@ -0,0 +1,53 @@
{
"name": "punycode",
"version": "1.3.2",
"description": "A robust Punycode converter that fully complies to RFC 3492 and RFC 5891, and works on nearly all JavaScript platforms.",
"homepage": "https://mths.be/punycode",
"main": "punycode.js",
"keywords": [
"punycode",
"unicode",
"idn",
"idna",
"dns",
"url",
"domain"
],
"license": "MIT",
"author": {
"name": "Mathias Bynens",
"url": "https://mathiasbynens.be/"
},
"contributors": [
{
"name": "Mathias Bynens",
"url": "https://mathiasbynens.be/"
},
{
"name": "John-David Dalton",
"url": "http://allyoucanleet.com/"
}
],
"repository": {
"type": "git",
"url": "https://github.com/bestiejs/punycode.js.git"
},
"bugs": "https://github.com/bestiejs/punycode.js/issues",
"files": [
"LICENSE-MIT.txt",
"punycode.js"
],
"scripts": {
"test": "node tests/tests.js"
},
"devDependencies": {
"coveralls": "^2.10.1",
"grunt": "^0.4.5",
"grunt-contrib-uglify": "^0.5.0",
"grunt-shell": "^0.7.0",
"istanbul": "^0.2.13",
"qunit-extras": "^1.2.0",
"qunitjs": "~1.11.0",
"requirejs": "^2.1.14"
}
}

530
node_modules/url/node_modules/punycode/punycode.js generated vendored Normal file
View File

@ -0,0 +1,530 @@
/*! https://mths.be/punycode v1.3.2 by @mathias */
;(function(root) {
/** Detect free variables */
var freeExports = typeof exports == 'object' && exports &&
!exports.nodeType && exports;
var freeModule = typeof module == 'object' && module &&
!module.nodeType && module;
var freeGlobal = typeof global == 'object' && global;
if (
freeGlobal.global === freeGlobal ||
freeGlobal.window === freeGlobal ||
freeGlobal.self === freeGlobal
) {
root = freeGlobal;
}
/**
* The `punycode` object.
* @name punycode
* @type Object
*/
var punycode,
/** Highest positive signed 32-bit float value */
maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1
/** Bootstring parameters */
base = 36,
tMin = 1,
tMax = 26,
skew = 38,
damp = 700,
initialBias = 72,
initialN = 128, // 0x80
delimiter = '-', // '\x2D'
/** Regular expressions */
regexPunycode = /^xn--/,
regexNonASCII = /[^\x20-\x7E]/, // unprintable ASCII chars + non-ASCII chars
regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g, // RFC 3490 separators
/** Error messages */
errors = {
'overflow': 'Overflow: input needs wider integers to process',
'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
'invalid-input': 'Invalid input'
},
/** Convenience shortcuts */
baseMinusTMin = base - tMin,
floor = Math.floor,
stringFromCharCode = String.fromCharCode,
/** Temporary variable */
key;
/*--------------------------------------------------------------------------*/
/**
* A generic error utility function.
* @private
* @param {String} type The error type.
* @returns {Error} Throws a `RangeError` with the applicable error message.
*/
function error(type) {
throw RangeError(errors[type]);
}
/**
* A generic `Array#map` utility function.
* @private
* @param {Array} array The array to iterate over.
* @param {Function} callback The function that gets called for every array
* item.
* @returns {Array} A new array of values returned by the callback function.
*/
function map(array, fn) {
var length = array.length;
var result = [];
while (length--) {
result[length] = fn(array[length]);
}
return result;
}
/**
* A simple `Array#map`-like wrapper to work with domain name strings or email
* addresses.
* @private
* @param {String} domain The domain name or email address.
* @param {Function} callback The function that gets called for every
* character.
* @returns {Array} A new string of characters returned by the callback
* function.
*/
function mapDomain(string, fn) {
var parts = string.split('@');
var result = '';
if (parts.length > 1) {
// In email addresses, only the domain name should be punycoded. Leave
// the local part (i.e. everything up to `@`) intact.
result = parts[0] + '@';
string = parts[1];
}
// Avoid `split(regex)` for IE8 compatibility. See #17.
string = string.replace(regexSeparators, '\x2E');
var labels = string.split('.');
var encoded = map(labels, fn).join('.');
return result + encoded;
}
/**
* Creates an array containing the numeric code points of each Unicode
* character in the string. While JavaScript uses UCS-2 internally,
* this function will convert a pair of surrogate halves (each of which
* UCS-2 exposes as separate characters) into a single code point,
* matching UTF-16.
* @see `punycode.ucs2.encode`
* @see <https://mathiasbynens.be/notes/javascript-encoding>
* @memberOf punycode.ucs2
* @name decode
* @param {String} string The Unicode input string (UCS-2).
* @returns {Array} The new array of code points.
*/
function ucs2decode(string) {
var output = [],
counter = 0,
length = string.length,
value,
extra;
while (counter < length) {
value = string.charCodeAt(counter++);
if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
// high surrogate, and there is a next character
extra = string.charCodeAt(counter++);
if ((extra & 0xFC00) == 0xDC00) { // low surrogate
output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
} else {
// unmatched surrogate; only append this code unit, in case the next
// code unit is the high surrogate of a surrogate pair
output.push(value);
counter--;
}
} else {
output.push(value);
}
}
return output;
}
/**
* Creates a string based on an array of numeric code points.
* @see `punycode.ucs2.decode`
* @memberOf punycode.ucs2
* @name encode
* @param {Array} codePoints The array of numeric code points.
* @returns {String} The new Unicode string (UCS-2).
*/
function ucs2encode(array) {
return map(array, function(value) {
var output = '';
if (value > 0xFFFF) {
value -= 0x10000;
output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
value = 0xDC00 | value & 0x3FF;
}
output += stringFromCharCode(value);
return output;
}).join('');
}
/**
* Converts a basic code point into a digit/integer.
* @see `digitToBasic()`
* @private
* @param {Number} codePoint The basic numeric code point value.
* @returns {Number} The numeric value of a basic code point (for use in
* representing integers) in the range `0` to `base - 1`, or `base` if
* the code point does not represent a value.
*/
function basicToDigit(codePoint) {
if (codePoint - 48 < 10) {
return codePoint - 22;
}
if (codePoint - 65 < 26) {
return codePoint - 65;
}
if (codePoint - 97 < 26) {
return codePoint - 97;
}
return base;
}
/**
* Converts a digit/integer into a basic code point.
* @see `basicToDigit()`
* @private
* @param {Number} digit The numeric value of a basic code point.
* @returns {Number} The basic code point whose value (when used for
* representing integers) is `digit`, which needs to be in the range
* `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
* used; else, the lowercase form is used. The behavior is undefined
* if `flag` is non-zero and `digit` has no uppercase form.
*/
function digitToBasic(digit, flag) {
// 0..25 map to ASCII a..z or A..Z
// 26..35 map to ASCII 0..9
return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
}
/**
* Bias adaptation function as per section 3.4 of RFC 3492.
* http://tools.ietf.org/html/rfc3492#section-3.4
* @private
*/
function adapt(delta, numPoints, firstTime) {
var k = 0;
delta = firstTime ? floor(delta / damp) : delta >> 1;
delta += floor(delta / numPoints);
for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {
delta = floor(delta / baseMinusTMin);
}
return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
}
/**
* Converts a Punycode string of ASCII-only symbols to a string of Unicode
* symbols.
* @memberOf punycode
* @param {String} input The Punycode string of ASCII-only symbols.
* @returns {String} The resulting string of Unicode symbols.
*/
function decode(input) {
// Don't use UCS-2
var output = [],
inputLength = input.length,
out,
i = 0,
n = initialN,
bias = initialBias,
basic,
j,
index,
oldi,
w,
k,
digit,
t,
/** Cached calculation results */
baseMinusT;
// Handle the basic code points: let `basic` be the number of input code
// points before the last delimiter, or `0` if there is none, then copy
// the first basic code points to the output.
basic = input.lastIndexOf(delimiter);
if (basic < 0) {
basic = 0;
}
for (j = 0; j < basic; ++j) {
// if it's not a basic code point
if (input.charCodeAt(j) >= 0x80) {
error('not-basic');
}
output.push(input.charCodeAt(j));
}
// Main decoding loop: start just after the last delimiter if any basic code
// points were copied; start at the beginning otherwise.
for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
// `index` is the index of the next character to be consumed.
// Decode a generalized variable-length integer into `delta`,
// which gets added to `i`. The overflow checking is easier
// if we increase `i` as we go, then subtract off its starting
// value at the end to obtain `delta`.
for (oldi = i, w = 1, k = base; /* no condition */; k += base) {
if (index >= inputLength) {
error('invalid-input');
}
digit = basicToDigit(input.charCodeAt(index++));
if (digit >= base || digit > floor((maxInt - i) / w)) {
error('overflow');
}
i += digit * w;
t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
if (digit < t) {
break;
}
baseMinusT = base - t;
if (w > floor(maxInt / baseMinusT)) {
error('overflow');
}
w *= baseMinusT;
}
out = output.length + 1;
bias = adapt(i - oldi, out, oldi == 0);
// `i` was supposed to wrap around from `out` to `0`,
// incrementing `n` each time, so we'll fix that now:
if (floor(i / out) > maxInt - n) {
error('overflow');
}
n += floor(i / out);
i %= out;
// Insert `n` at position `i` of the output
output.splice(i++, 0, n);
}
return ucs2encode(output);
}
/**
* Converts a string of Unicode symbols (e.g. a domain name label) to a
* Punycode string of ASCII-only symbols.
* @memberOf punycode
* @param {String} input The string of Unicode symbols.
* @returns {String} The resulting Punycode string of ASCII-only symbols.
*/
function encode(input) {
var n,
delta,
handledCPCount,
basicLength,
bias,
j,
m,
q,
k,
t,
currentValue,
output = [],
/** `inputLength` will hold the number of code points in `input`. */
inputLength,
/** Cached calculation results */
handledCPCountPlusOne,
baseMinusT,
qMinusT;
// Convert the input in UCS-2 to Unicode
input = ucs2decode(input);
// Cache the length
inputLength = input.length;
// Initialize the state
n = initialN;
delta = 0;
bias = initialBias;
// Handle the basic code points
for (j = 0; j < inputLength; ++j) {
currentValue = input[j];
if (currentValue < 0x80) {
output.push(stringFromCharCode(currentValue));
}
}
handledCPCount = basicLength = output.length;
// `handledCPCount` is the number of code points that have been handled;
// `basicLength` is the number of basic code points.
// Finish the basic string - if it is not empty - with a delimiter
if (basicLength) {
output.push(delimiter);
}
// Main encoding loop:
while (handledCPCount < inputLength) {
// All non-basic code points < n have been handled already. Find the next
// larger one:
for (m = maxInt, j = 0; j < inputLength; ++j) {
currentValue = input[j];
if (currentValue >= n && currentValue < m) {
m = currentValue;
}
}
// Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
// but guard against overflow
handledCPCountPlusOne = handledCPCount + 1;
if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
error('overflow');
}
delta += (m - n) * handledCPCountPlusOne;
n = m;
for (j = 0; j < inputLength; ++j) {
currentValue = input[j];
if (currentValue < n && ++delta > maxInt) {
error('overflow');
}
if (currentValue == n) {
// Represent delta as a generalized variable-length integer
for (q = delta, k = base; /* no condition */; k += base) {
t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
if (q < t) {
break;
}
qMinusT = q - t;
baseMinusT = base - t;
output.push(
stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
);
q = floor(qMinusT / baseMinusT);
}
output.push(stringFromCharCode(digitToBasic(q, 0)));
bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
delta = 0;
++handledCPCount;
}
}
++delta;
++n;
}
return output.join('');
}
/**
* Converts a Punycode string representing a domain name or an email address
* to Unicode. Only the Punycoded parts of the input will be converted, i.e.
* it doesn't matter if you call it on a string that has already been
* converted to Unicode.
* @memberOf punycode
* @param {String} input The Punycoded domain name or email address to
* convert to Unicode.
* @returns {String} The Unicode representation of the given Punycode
* string.
*/
function toUnicode(input) {
return mapDomain(input, function(string) {
return regexPunycode.test(string)
? decode(string.slice(4).toLowerCase())
: string;
});
}
/**
* Converts a Unicode string representing a domain name or an email address to
* Punycode. Only the non-ASCII parts of the domain name will be converted,
* i.e. it doesn't matter if you call it with a domain that's already in
* ASCII.
* @memberOf punycode
* @param {String} input The domain name or email address to convert, as a
* Unicode string.
* @returns {String} The Punycode representation of the given domain name or
* email address.
*/
function toASCII(input) {
return mapDomain(input, function(string) {
return regexNonASCII.test(string)
? 'xn--' + encode(string)
: string;
});
}
/*--------------------------------------------------------------------------*/
/** Define the public API */
punycode = {
/**
* A string representing the current Punycode.js version number.
* @memberOf punycode
* @type String
*/
'version': '1.3.2',
/**
* An object of methods to convert from JavaScript's internal character
* representation (UCS-2) to Unicode code points, and back.
* @see <https://mathiasbynens.be/notes/javascript-encoding>
* @memberOf punycode
* @type Object
*/
'ucs2': {
'decode': ucs2decode,
'encode': ucs2encode
},
'decode': decode,
'encode': encode,
'toASCII': toASCII,
'toUnicode': toUnicode
};
/** Expose `punycode` */
// Some AMD build optimizers, like r.js, check for specific condition patterns
// like the following:
if (
typeof define == 'function' &&
typeof define.amd == 'object' &&
define.amd
) {
define('punycode', function() {
return punycode;
});
} else if (freeExports && freeModule) {
if (module.exports == freeExports) { // in Node.js or RingoJS v0.8.0+
freeModule.exports = punycode;
} else { // in Narwhal or RingoJS v0.7.0-
for (key in punycode) {
punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]);
}
}
} else { // in Rhino or a web browser
root.punycode = punycode;
}
}(this));

24
node_modules/url/package.json generated vendored Normal file
View File

@ -0,0 +1,24 @@
{
"name": "url",
"description": "The core `url` packaged standalone for use with Browserify.",
"version": "0.11.0",
"dependencies": {
"punycode": "1.3.2",
"querystring": "0.2.0"
},
"main": "./url.js",
"devDependencies": {
"assert": "1.1.1",
"mocha": "1.18.2",
"zuul": "3.3.0"
},
"scripts": {
"test": "mocha --ui qunit test.js && zuul -- test.js",
"test-local": "zuul --local -- test.js"
},
"repository": {
"type": "git",
"url": "https://github.com/defunctzombie/node-url.git"
},
"license": "MIT"
}

1599
node_modules/url/test.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

732
node_modules/url/url.js generated vendored Normal file
View File

@ -0,0 +1,732 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// 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.
'use strict';
var punycode = require('punycode');
var util = require('./util');
exports.parse = urlParse;
exports.resolve = urlResolve;
exports.resolveObject = urlResolveObject;
exports.format = urlFormat;
exports.Url = Url;
function Url() {
this.protocol = null;
this.slashes = null;
this.auth = null;
this.host = null;
this.port = null;
this.hostname = null;
this.hash = null;
this.search = null;
this.query = null;
this.pathname = null;
this.path = null;
this.href = null;
}
// Reference: RFC 3986, RFC 1808, RFC 2396
// define these here so at least they only have to be
// compiled once on the first module load.
var protocolPattern = /^([a-z0-9.+-]+:)/i,
portPattern = /:[0-9]*$/,
// Special case for a simple path URL
simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,
// RFC 2396: characters reserved for delimiting URLs.
// We actually just auto-escape these.
delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
// RFC 2396: characters not allowed for various reasons.
unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims),
// Allowed by RFCs, but cause of XSS attacks. Always escape these.
autoEscape = ['\''].concat(unwise),
// Characters that are never ever allowed in a hostname.
// Note that any invalid chars are also handled, but these
// are the ones that are *expected* to be seen, so we fast-path
// them.
nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape),
hostEndingChars = ['/', '?', '#'],
hostnameMaxLen = 255,
hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/,
hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/,
// protocols that can allow "unsafe" and "unwise" chars.
unsafeProtocol = {
'javascript': true,
'javascript:': true
},
// protocols that never have a hostname.
hostlessProtocol = {
'javascript': true,
'javascript:': true
},
// protocols that always contain a // bit.
slashedProtocol = {
'http': true,
'https': true,
'ftp': true,
'gopher': true,
'file': true,
'http:': true,
'https:': true,
'ftp:': true,
'gopher:': true,
'file:': true
},
querystring = require('querystring');
function urlParse(url, parseQueryString, slashesDenoteHost) {
if (url && util.isObject(url) && url instanceof Url) return url;
var u = new Url;
u.parse(url, parseQueryString, slashesDenoteHost);
return u;
}
Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
if (!util.isString(url)) {
throw new TypeError("Parameter 'url' must be a string, not " + typeof url);
}
// Copy chrome, IE, opera backslash-handling behavior.
// Back slashes before the query string get converted to forward slashes
// See: https://code.google.com/p/chromium/issues/detail?id=25916
var queryIndex = url.indexOf('?'),
splitter =
(queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#',
uSplit = url.split(splitter),
slashRegex = /\\/g;
uSplit[0] = uSplit[0].replace(slashRegex, '/');
url = uSplit.join(splitter);
var rest = url;
// trim before proceeding.
// This is to support parse stuff like " http://foo.com \n"
rest = rest.trim();
if (!slashesDenoteHost && url.split('#').length === 1) {
// Try fast path regexp
var simplePath = simplePathPattern.exec(rest);
if (simplePath) {
this.path = rest;
this.href = rest;
this.pathname = simplePath[1];
if (simplePath[2]) {
this.search = simplePath[2];
if (parseQueryString) {
this.query = querystring.parse(this.search.substr(1));
} else {
this.query = this.search.substr(1);
}
} else if (parseQueryString) {
this.search = '';
this.query = {};
}
return this;
}
}
var proto = protocolPattern.exec(rest);
if (proto) {
proto = proto[0];
var lowerProto = proto.toLowerCase();
this.protocol = lowerProto;
rest = rest.substr(proto.length);
}
// figure out if it's got a host
// user@server is *always* interpreted as a hostname, and url
// resolution will treat //foo/bar as host=foo,path=bar because that's
// how the browser resolves relative URLs.
if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) {
var slashes = rest.substr(0, 2) === '//';
if (slashes && !(proto && hostlessProtocol[proto])) {
rest = rest.substr(2);
this.slashes = true;
}
}
if (!hostlessProtocol[proto] &&
(slashes || (proto && !slashedProtocol[proto]))) {
// there's a hostname.
// the first instance of /, ?, ;, or # ends the host.
//
// If there is an @ in the hostname, then non-host chars *are* allowed
// to the left of the last @ sign, unless some host-ending character
// comes *before* the @-sign.
// URLs are obnoxious.
//
// ex:
// http://a@b@c/ => user:a@b host:c
// http://a@b?@c => user:a host:c path:/?@c
// v0.12 TODO(isaacs): This is not quite how Chrome does things.
// Review our test case against browsers more comprehensively.
// find the first instance of any hostEndingChars
var hostEnd = -1;
for (var i = 0; i < hostEndingChars.length; i++) {
var hec = rest.indexOf(hostEndingChars[i]);
if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
hostEnd = hec;
}
// at this point, either we have an explicit point where the
// auth portion cannot go past, or the last @ char is the decider.
var auth, atSign;
if (hostEnd === -1) {
// atSign can be anywhere.
atSign = rest.lastIndexOf('@');
} else {
// atSign must be in auth portion.
// http://a@b/c@d => host:b auth:a path:/c@d
atSign = rest.lastIndexOf('@', hostEnd);
}
// Now we have a portion which is definitely the auth.
// Pull that off.
if (atSign !== -1) {
auth = rest.slice(0, atSign);
rest = rest.slice(atSign + 1);
this.auth = decodeURIComponent(auth);
}
// the host is the remaining to the left of the first non-host char
hostEnd = -1;
for (var i = 0; i < nonHostChars.length; i++) {
var hec = rest.indexOf(nonHostChars[i]);
if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
hostEnd = hec;
}
// if we still have not hit it, then the entire thing is a host.
if (hostEnd === -1)
hostEnd = rest.length;
this.host = rest.slice(0, hostEnd);
rest = rest.slice(hostEnd);
// pull out port.
this.parseHost();
// we've indicated that there is a hostname,
// so even if it's empty, it has to be present.
this.hostname = this.hostname || '';
// if hostname begins with [ and ends with ]
// assume that it's an IPv6 address.
var ipv6Hostname = this.hostname[0] === '[' &&
this.hostname[this.hostname.length - 1] === ']';
// validate a little.
if (!ipv6Hostname) {
var hostparts = this.hostname.split(/\./);
for (var i = 0, l = hostparts.length; i < l; i++) {
var part = hostparts[i];
if (!part) continue;
if (!part.match(hostnamePartPattern)) {
var newpart = '';
for (var j = 0, k = part.length; j < k; j++) {
if (part.charCodeAt(j) > 127) {
// we replace non-ASCII char with a temporary placeholder
// we need this to make sure size of hostname is not
// broken by replacing non-ASCII by nothing
newpart += 'x';
} else {
newpart += part[j];
}
}
// we test again with ASCII char only
if (!newpart.match(hostnamePartPattern)) {
var validParts = hostparts.slice(0, i);
var notHost = hostparts.slice(i + 1);
var bit = part.match(hostnamePartStart);
if (bit) {
validParts.push(bit[1]);
notHost.unshift(bit[2]);
}
if (notHost.length) {
rest = '/' + notHost.join('.') + rest;
}
this.hostname = validParts.join('.');
break;
}
}
}
}
if (this.hostname.length > hostnameMaxLen) {
this.hostname = '';
} else {
// hostnames are always lower case.
this.hostname = this.hostname.toLowerCase();
}
if (!ipv6Hostname) {
// IDNA Support: Returns a punycoded representation of "domain".
// It only converts parts of the domain name that
// have non-ASCII characters, i.e. it doesn't matter if
// you call it with a domain that already is ASCII-only.
this.hostname = punycode.toASCII(this.hostname);
}
var p = this.port ? ':' + this.port : '';
var h = this.hostname || '';
this.host = h + p;
this.href += this.host;
// strip [ and ] from the hostname
// the host field still retains them, though
if (ipv6Hostname) {
this.hostname = this.hostname.substr(1, this.hostname.length - 2);
if (rest[0] !== '/') {
rest = '/' + rest;
}
}
}
// now rest is set to the post-host stuff.
// chop off any delim chars.
if (!unsafeProtocol[lowerProto]) {
// First, make 100% sure that any "autoEscape" chars get
// escaped, even if encodeURIComponent doesn't think they
// need to be.
for (var i = 0, l = autoEscape.length; i < l; i++) {
var ae = autoEscape[i];
if (rest.indexOf(ae) === -1)
continue;
var esc = encodeURIComponent(ae);
if (esc === ae) {
esc = escape(ae);
}
rest = rest.split(ae).join(esc);
}
}
// chop off from the tail first.
var hash = rest.indexOf('#');
if (hash !== -1) {
// got a fragment string.
this.hash = rest.substr(hash);
rest = rest.slice(0, hash);
}
var qm = rest.indexOf('?');
if (qm !== -1) {
this.search = rest.substr(qm);
this.query = rest.substr(qm + 1);
if (parseQueryString) {
this.query = querystring.parse(this.query);
}
rest = rest.slice(0, qm);
} else if (parseQueryString) {
// no query string, but parseQueryString still requested
this.search = '';
this.query = {};
}
if (rest) this.pathname = rest;
if (slashedProtocol[lowerProto] &&
this.hostname && !this.pathname) {
this.pathname = '/';
}
//to support http.request
if (this.pathname || this.search) {
var p = this.pathname || '';
var s = this.search || '';
this.path = p + s;
}
// finally, reconstruct the href based on what has been validated.
this.href = this.format();
return this;
};
// format a parsed object into a url string
function urlFormat(obj) {
// ensure it's an object, and not a string url.
// If it's an obj, this is a no-op.
// this way, you can call url_format() on strings
// to clean up potentially wonky urls.
if (util.isString(obj)) obj = urlParse(obj);
if (!(obj instanceof Url)) return Url.prototype.format.call(obj);
return obj.format();
}
Url.prototype.format = function() {
var auth = this.auth || '';
if (auth) {
auth = encodeURIComponent(auth);
auth = auth.replace(/%3A/i, ':');
auth += '@';
}
var protocol = this.protocol || '',
pathname = this.pathname || '',
hash = this.hash || '',
host = false,
query = '';
if (this.host) {
host = auth + this.host;
} else if (this.hostname) {
host = auth + (this.hostname.indexOf(':') === -1 ?
this.hostname :
'[' + this.hostname + ']');
if (this.port) {
host += ':' + this.port;
}
}
if (this.query &&
util.isObject(this.query) &&
Object.keys(this.query).length) {
query = querystring.stringify(this.query);
}
var search = this.search || (query && ('?' + query)) || '';
if (protocol && protocol.substr(-1) !== ':') protocol += ':';
// only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
// unless they had them to begin with.
if (this.slashes ||
(!protocol || slashedProtocol[protocol]) && host !== false) {
host = '//' + (host || '');
if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname;
} else if (!host) {
host = '';
}
if (hash && hash.charAt(0) !== '#') hash = '#' + hash;
if (search && search.charAt(0) !== '?') search = '?' + search;
pathname = pathname.replace(/[?#]/g, function(match) {
return encodeURIComponent(match);
});
search = search.replace('#', '%23');
return protocol + host + pathname + search + hash;
};
function urlResolve(source, relative) {
return urlParse(source, false, true).resolve(relative);
}
Url.prototype.resolve = function(relative) {
return this.resolveObject(urlParse(relative, false, true)).format();
};
function urlResolveObject(source, relative) {
if (!source) return relative;
return urlParse(source, false, true).resolveObject(relative);
}
Url.prototype.resolveObject = function(relative) {
if (util.isString(relative)) {
var rel = new Url();
rel.parse(relative, false, true);
relative = rel;
}
var result = new Url();
var tkeys = Object.keys(this);
for (var tk = 0; tk < tkeys.length; tk++) {
var tkey = tkeys[tk];
result[tkey] = this[tkey];
}
// hash is always overridden, no matter what.
// even href="" will remove it.
result.hash = relative.hash;
// if the relative url is empty, then there's nothing left to do here.
if (relative.href === '') {
result.href = result.format();
return result;
}
// hrefs like //foo/bar always cut to the protocol.
if (relative.slashes && !relative.protocol) {
// take everything except the protocol from relative
var rkeys = Object.keys(relative);
for (var rk = 0; rk < rkeys.length; rk++) {
var rkey = rkeys[rk];
if (rkey !== 'protocol')
result[rkey] = relative[rkey];
}
//urlParse appends trailing / to urls like http://www.example.com
if (slashedProtocol[result.protocol] &&
result.hostname && !result.pathname) {
result.path = result.pathname = '/';
}
result.href = result.format();
return result;
}
if (relative.protocol && relative.protocol !== result.protocol) {
// if it's a known url protocol, then changing
// the protocol does weird things
// first, if it's not file:, then we MUST have a host,
// and if there was a path
// to begin with, then we MUST have a path.
// if it is file:, then the host is dropped,
// because that's known to be hostless.
// anything else is assumed to be absolute.
if (!slashedProtocol[relative.protocol]) {
var keys = Object.keys(relative);
for (var v = 0; v < keys.length; v++) {
var k = keys[v];
result[k] = relative[k];
}
result.href = result.format();
return result;
}
result.protocol = relative.protocol;
if (!relative.host && !hostlessProtocol[relative.protocol]) {
var relPath = (relative.pathname || '').split('/');
while (relPath.length && !(relative.host = relPath.shift()));
if (!relative.host) relative.host = '';
if (!relative.hostname) relative.hostname = '';
if (relPath[0] !== '') relPath.unshift('');
if (relPath.length < 2) relPath.unshift('');
result.pathname = relPath.join('/');
} else {
result.pathname = relative.pathname;
}
result.search = relative.search;
result.query = relative.query;
result.host = relative.host || '';
result.auth = relative.auth;
result.hostname = relative.hostname || relative.host;
result.port = relative.port;
// to support http.request
if (result.pathname || result.search) {
var p = result.pathname || '';
var s = result.search || '';
result.path = p + s;
}
result.slashes = result.slashes || relative.slashes;
result.href = result.format();
return result;
}
var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'),
isRelAbs = (
relative.host ||
relative.pathname && relative.pathname.charAt(0) === '/'
),
mustEndAbs = (isRelAbs || isSourceAbs ||
(result.host && relative.pathname)),
removeAllDots = mustEndAbs,
srcPath = result.pathname && result.pathname.split('/') || [],
relPath = relative.pathname && relative.pathname.split('/') || [],
psychotic = result.protocol && !slashedProtocol[result.protocol];
// if the url is a non-slashed url, then relative
// links like ../.. should be able
// to crawl up to the hostname, as well. This is strange.
// result.protocol has already been set by now.
// Later on, put the first path part into the host field.
if (psychotic) {
result.hostname = '';
result.port = null;
if (result.host) {
if (srcPath[0] === '') srcPath[0] = result.host;
else srcPath.unshift(result.host);
}
result.host = '';
if (relative.protocol) {
relative.hostname = null;
relative.port = null;
if (relative.host) {
if (relPath[0] === '') relPath[0] = relative.host;
else relPath.unshift(relative.host);
}
relative.host = null;
}
mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
}
if (isRelAbs) {
// it's absolute.
result.host = (relative.host || relative.host === '') ?
relative.host : result.host;
result.hostname = (relative.hostname || relative.hostname === '') ?
relative.hostname : result.hostname;
result.search = relative.search;
result.query = relative.query;
srcPath = relPath;
// fall through to the dot-handling below.
} else if (relPath.length) {
// it's relative
// throw away the existing file, and take the new path instead.
if (!srcPath) srcPath = [];
srcPath.pop();
srcPath = srcPath.concat(relPath);
result.search = relative.search;
result.query = relative.query;
} else if (!util.isNullOrUndefined(relative.search)) {
// just pull out the search.
// like href='?foo'.
// Put this after the other two cases because it simplifies the booleans
if (psychotic) {
result.hostname = result.host = srcPath.shift();
//occationaly the auth can get stuck only in host
//this especially happens in cases like
//url.resolveObject('mailto:local1@domain1', 'local2@domain2')
var authInHost = result.host && result.host.indexOf('@') > 0 ?
result.host.split('@') : false;
if (authInHost) {
result.auth = authInHost.shift();
result.host = result.hostname = authInHost.shift();
}
}
result.search = relative.search;
result.query = relative.query;
//to support http.request
if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
result.path = (result.pathname ? result.pathname : '') +
(result.search ? result.search : '');
}
result.href = result.format();
return result;
}
if (!srcPath.length) {
// no path at all. easy.
// we've already handled the other stuff above.
result.pathname = null;
//to support http.request
if (result.search) {
result.path = '/' + result.search;
} else {
result.path = null;
}
result.href = result.format();
return result;
}
// if a url ENDs in . or .., then it must get a trailing slash.
// however, if it ends in anything else non-slashy,
// then it must NOT get a trailing slash.
var last = srcPath.slice(-1)[0];
var hasTrailingSlash = (
(result.host || relative.host || srcPath.length > 1) &&
(last === '.' || last === '..') || last === '');
// strip single dots, resolve double dots to parent dir
// if the path tries to go above the root, `up` ends up > 0
var up = 0;
for (var i = srcPath.length; i >= 0; i--) {
last = srcPath[i];
if (last === '.') {
srcPath.splice(i, 1);
} else if (last === '..') {
srcPath.splice(i, 1);
up++;
} else if (up) {
srcPath.splice(i, 1);
up--;
}
}
// if the path is allowed to go above the root, restore leading ..s
if (!mustEndAbs && !removeAllDots) {
for (; up--; up) {
srcPath.unshift('..');
}
}
if (mustEndAbs && srcPath[0] !== '' &&
(!srcPath[0] || srcPath[0].charAt(0) !== '/')) {
srcPath.unshift('');
}
if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
srcPath.push('');
}
var isAbsolute = srcPath[0] === '' ||
(srcPath[0] && srcPath[0].charAt(0) === '/');
// put the host back
if (psychotic) {
result.hostname = result.host = isAbsolute ? '' :
srcPath.length ? srcPath.shift() : '';
//occationaly the auth can get stuck only in host
//this especially happens in cases like
//url.resolveObject('mailto:local1@domain1', 'local2@domain2')
var authInHost = result.host && result.host.indexOf('@') > 0 ?
result.host.split('@') : false;
if (authInHost) {
result.auth = authInHost.shift();
result.host = result.hostname = authInHost.shift();
}
}
mustEndAbs = mustEndAbs || (result.host && srcPath.length);
if (mustEndAbs && !isAbsolute) {
srcPath.unshift('');
}
if (!srcPath.length) {
result.pathname = null;
result.path = null;
} else {
result.pathname = srcPath.join('/');
}
//to support request.http
if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
result.path = (result.pathname ? result.pathname : '') +
(result.search ? result.search : '');
}
result.auth = relative.auth || result.auth;
result.slashes = result.slashes || relative.slashes;
result.href = result.format();
return result;
};
Url.prototype.parseHost = function() {
var host = this.host;
var port = portPattern.exec(host);
if (port) {
port = port[0];
if (port !== ':') {
this.port = port.substr(1);
}
host = host.substr(0, host.length - port.length);
}
if (host) this.hostname = host;
};

16
node_modules/url/util.js generated vendored Normal file
View File

@ -0,0 +1,16 @@
'use strict';
module.exports = {
isString: function(arg) {
return typeof(arg) === 'string';
},
isObject: function(arg) {
return typeof(arg) === 'object' && arg !== null;
},
isNull: function(arg) {
return arg === null;
},
isNullOrUndefined: function(arg) {
return arg == null;
}
};

6
node_modules/valid-url/.jshintrc generated vendored Normal file
View File

@ -0,0 +1,6 @@
{
"node" : true,
"undef": true,
"unused": true,
"indent": 4
}

5
node_modules/valid-url/.travis.yml generated vendored Normal file
View File

@ -0,0 +1,5 @@
language: node_js
node_js:
- "0.6"
- "0.8"
- "0.10"

20
node_modules/valid-url/LICENSE generated vendored Normal file
View File

@ -0,0 +1,20 @@
Copyright (c) 2013 Odysseas Tsatalos and oDesk Corporation
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.

10
node_modules/valid-url/Makefile generated vendored Normal file
View File

@ -0,0 +1,10 @@
TAP=node_modules/.bin/tap
LINT=node_modules/.bin/jshint
test: lint
$(TAP) test/*.js
lint:
$(LINT) index.js
$(LINT) test/*.js

134
node_modules/valid-url/README.md generated vendored Normal file
View File

@ -0,0 +1,134 @@
URI validation functions
==
[![Build Status](https://travis-ci.org/ogt/valid-url.png)](https://travis-ci.org/ogt/valid-url)
## Synopsis
Common url validation methods
```
var validUrl = require('valid-url');
if (validUrl.isUri(suspect)){
console.log('Looks like an URI');
} else {
console.log('Not a URI');
}
```
Replicates the functionality of Richard Sonnen <sonnen@richardsonnen.com> perl module :
http://search.cpan.org/~sonnen/Data-Validate-URI-0.01/lib/Data/Validate/URI.pm [full code here](http://anonscm.debian.org/gitweb/?p=users/dom/libdata-validate-uri-perl.git)
into a nodejs module. Translated practically line by line from perl.
It passes all the original tests.
## Description
(copied from original perl module)
> This module collects common URI validation routines to make input validation, and untainting easier and more readable.
> All functions return an untainted value if the test passes, and undef if it fails. This means that you should always check for a defined status explicitly. Don't assume the return will be true.
> The value to test is always the first (and often only) argument.
> There are a number of other URI validation modules out there as well (see below.) This one focuses on being fast, lightweight, and relatively 'real-world'. i.e. it's good if you want to check user input, and don't need to parse out the URI/URL into chunks.
> Right now the module focuses on HTTP URIs, since they're arguably the most common. If you have a specialized scheme you'd like to have supported, let me know.
## Installation
```
npm install valid-url
```
## Methods
```javascript
/*
* @Function isUri(value)
*
* @Synopsis is the value a well-formed uri?
* @Description
Returns the untainted URI if the test value appears to be well-formed. Note that
you may really want one of the more practical methods like is_http_uri or is_https_uri,
since the URI standard (RFC 3986) allows a lot of things you probably don't want.
* @Arguments
* value The potential URI to test.
*
* @Returns The untainted RFC 3986 URI on success, undefined on failure.
* @Notes
This function does not make any attempt to check whether the URI is accessible
or 'makes sense' in any meaningful way. It just checks that it is formatted
correctly.
*
*/
/*
* @Function isHttpUri(value)
* @Synopsis is the value a well-formed HTTP uri?
* @Description
Specialized version of isUri() that only likes http:// urls. As a result, it can
also do a much more thorough job validating. Also, unlike isUri() it is more
concerned with only allowing real-world URIs through. Things like relative
hostnames are allowed by the standards, but probably aren't wise. Conversely,
null paths aren't allowed per RFC 2616 (should be '/' instead), but are allowed
by this function.
This function only works for fully-qualified URIs. /bob.html won't work.
See RFC 3986 for the appropriate method to turn a relative URI into an absolute
one given its context.
Returns the untainted URI if the test value appears to be well-formed.
Note that you probably want to either call this in combo with is_https_uri(). i.e.
if(isHttpUri(uri) || isHttpsUri(uri)) console.log('Good');
or use the convenience method isWebUri which is equivalent.
* @Arguments
* value The potential URI to test.
*
* @Returns The untainted RFC 3986 URI on success, undefined on failure.
* @Notes
This function does not make any attempt to check whether the URI is accessible
or 'makes sense' in any meaningful way. It just checks that it is formatted
correctly.
*/
/*
* @Function isHttpsUri(value)
* @Synopsis is the value a well-formed HTTPS uri?
* @Description
See is_http_uri() for details. This version only likes the https URI scheme.
Otherwise it's identical to is_http_uri()
* @Arguments
* value The potential URI to test.
*
* @Returns The untainted RFC 3986 URI on success, undefined on failure.
* @Notes
This function does not make any attempt to check whether the URI is accessible
or 'makes sense' in any meaningful way. It just checks that it is formatted
correctly.
*/
/*
* @Function isWebUri(value)
* @Synopsis is the value a well-formed HTTP or HTTPS uri?
* @Description
This is just a convenience method that combines isHttpUri and isHttpsUri
to accept most common real-world URLs.
* @Arguments
* value The potential URI to test.
*
* @Returns The untainted RFC 3986 URI on success, undefined on failure.
* @Notes
This function does not make any attempt to check whether the URI is accessible
or 'makes sense' in any meaningful way. It just checks that it is formatted
correctly.
*/
```
## See also
RFC 3986, RFC 3966, RFC 4694, RFC 4759, RFC 4904

153
node_modules/valid-url/index.js generated vendored Normal file
View File

@ -0,0 +1,153 @@
(function(module) {
'use strict';
module.exports.is_uri = is_iri;
module.exports.is_http_uri = is_http_iri;
module.exports.is_https_uri = is_https_iri;
module.exports.is_web_uri = is_web_iri;
// Create aliases
module.exports.isUri = is_iri;
module.exports.isHttpUri = is_http_iri;
module.exports.isHttpsUri = is_https_iri;
module.exports.isWebUri = is_web_iri;
// private function
// internal URI spitter method - direct from RFC 3986
var splitUri = function(uri) {
var splitted = uri.match(/(?:([^:\/?#]+):)?(?:\/\/([^\/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/);
return splitted;
};
function is_iri(value) {
if (!value) {
return;
}
// check for illegal characters
if (/[^a-z0-9\:\/\?\#\[\]\@\!\$\&\'\(\)\*\+\,\;\=\.\-\_\~\%]/i.test(value)) return;
// check for hex escapes that aren't complete
if (/%[^0-9a-f]/i.test(value)) return;
if (/%[0-9a-f](:?[^0-9a-f]|$)/i.test(value)) return;
var splitted = [];
var scheme = '';
var authority = '';
var path = '';
var query = '';
var fragment = '';
var out = '';
// from RFC 3986
splitted = splitUri(value);
scheme = splitted[1];
authority = splitted[2];
path = splitted[3];
query = splitted[4];
fragment = splitted[5];
// scheme and path are required, though the path can be empty
if (!(scheme && scheme.length && path.length >= 0)) return;
// if authority is present, the path must be empty or begin with a /
if (authority && authority.length) {
if (!(path.length === 0 || /^\//.test(path))) return;
} else {
// if authority is not present, the path must not start with //
if (/^\/\//.test(path)) return;
}
// scheme must begin with a letter, then consist of letters, digits, +, ., or -
if (!/^[a-z][a-z0-9\+\-\.]*$/.test(scheme.toLowerCase())) return;
// re-assemble the URL per section 5.3 in RFC 3986
out += scheme + ':';
if (authority && authority.length) {
out += '//' + authority;
}
out += path;
if (query && query.length) {
out += '?' + query;
}
if (fragment && fragment.length) {
out += '#' + fragment;
}
return out;
}
function is_http_iri(value, allowHttps) {
if (!is_iri(value)) {
return;
}
var splitted = [];
var scheme = '';
var authority = '';
var path = '';
var port = '';
var query = '';
var fragment = '';
var out = '';
// from RFC 3986
splitted = splitUri(value);
scheme = splitted[1];
authority = splitted[2];
path = splitted[3];
query = splitted[4];
fragment = splitted[5];
if (!scheme) return;
if(allowHttps) {
if (scheme.toLowerCase() != 'https') return;
} else {
if (scheme.toLowerCase() != 'http') return;
}
// fully-qualified URIs must have an authority section that is
// a valid host
if (!authority) {
return;
}
// enable port component
if (/:(\d+)$/.test(authority)) {
port = authority.match(/:(\d+)$/)[0];
authority = authority.replace(/:\d+$/, '');
}
out += scheme + ':';
out += '//' + authority;
if (port) {
out += port;
}
out += path;
if(query && query.length){
out += '?' + query;
}
if(fragment && fragment.length){
out += '#' + fragment;
}
return out;
}
function is_https_iri(value) {
return is_http_iri(value, true);
}
function is_web_iri(value) {
return (is_http_iri(value) || is_https_iri(value));
}
})(module);

24
node_modules/valid-url/package.json generated vendored Normal file
View File

@ -0,0 +1,24 @@
{
"name": "valid-url",
"description": "URI validation functions",
"keywords": [
"url",
"validation",
"check",
"checker",
"pattern"
],
"version": "1.0.9",
"repository": {
"url": "git://github.com/ogt/valid-url.git"
},
"main": "index.js",
"scripts": {
"test": "make test"
},
"dependencies": {},
"devDependencies": {
"tap": "~0.4.3",
"jshint": "~2.1.4"
}
}

22
node_modules/valid-url/test/is_http_uri.js generated vendored Normal file
View File

@ -0,0 +1,22 @@
var test = require("tap").test,
is_http_uri = require('../').is_http_uri;
test("testing is_http_uri", function (t) {
// valid
t.ok(is_http_uri('http://www.richardsonnen.com/'), 'http://www.richardsonnen.com/');
t.ok(is_http_uri('http://www.richardsonnen.com'), 'http://www.richardsonnen.com');
t.ok(is_http_uri('http://www.richardsonnen.com/foo/bar/test.html'), 'http://www.richardsonnen.com/foo/bar/test.html');
t.ok(is_http_uri('http://www.richardsonnen.com/?foo=bar'), 'http://www.richardsonnen.com/?foo=bar');
t.ok(is_http_uri('http://www.richardsonnen.com:8080/test.html'), 'http://www.richardsonnen.com:8080/test.html');
t.ok(is_http_uri('http://example.w3.org/path%20with%20spaces.html'), 'http://example.w3.org/path%20with%20spaces.html');
t.ok(is_http_uri('http://192.168.0.1/'), 'http://192.168.0.1/');
// invalid
t.notOk(is_http_uri(''), "bad: ''");
t.notOk(is_http_uri('ftp://ftp.richardsonnen.com'), "bad: 'ftp://ftp.richardsonnen.com'");
t.notOk(is_http_uri('http:www.richardsonnen.com'), "bad: 'http:www.richardsonnen.com'");
t.notOk(is_http_uri('https://www.richardsonnen.com'), "bad: 'https://www.richardsonnen.com'");
t.end();
});

22
node_modules/valid-url/test/is_https_uri.js generated vendored Normal file
View File

@ -0,0 +1,22 @@
var test = require("tap").test,
is_https_uri = require('../').is_https_uri;
test("testing is_https_uri", function (t) {
// valid
t.ok(is_https_uri('https://www.richardsonnen.com/'), 'https://www.richardsonnen.com/');
t.ok(is_https_uri('https://www.richardsonnen.com'), 'https://www.richardsonnen.com');
t.ok(is_https_uri('https://www.richardsonnen.com/foo/bar/test.html'), 'https://www.richardsonnen.com/foo/bar/test.html');
t.ok(is_https_uri('https://www.richardsonnen.com/?foo=bar'), 'https://www.richardsonnen.com/?foo=bar');
t.ok(is_https_uri('https://www.richardsonnen.com:8080/test.html'), 'https://www.richardsonnen.com:8080/test.html');
t.ok(is_https_uri('https://example.w3.org/path%20with%20spaces.html'), 'http://example.w3.org/path%20with%20spaces.html');
t.ok(is_https_uri('https://192.168.0.1/'), 'http://192.168.0.1/');
// invalid
t.notOk(is_https_uri(''), "bad: ''");
t.notOk(is_https_uri('http://www.richardsonnen.com/'), 'http://www.richardsonnen.com/');
t.notOk(is_https_uri('ftp://ftp.richardsonnen.com'), "bad: 'ftp://ftp.richardsonnen.com'");
t.notOk(is_https_uri('https:www.richardsonnen.com'), "bad: 'https:www.richardsonnen.com'");
t.end();
});

35
node_modules/valid-url/test/is_uri.js generated vendored Normal file
View File

@ -0,0 +1,35 @@
var test = require("tap").test,
is_uri = require('../').is_uri;
test("testing is_uri", function (t) {
// valid - from RFC 3986 for the most part
t.ok(is_uri('http://localhost/'), 'http://localhost/');
t.ok(is_uri('http://example.w3.org/path%20with%20spaces.html'), 'http://example.w3.org/path%20with%20spaces.html');
t.ok(is_uri('http://example.w3.org/%20'), 'http://example.w3.org/%20');
t.ok(is_uri('ftp://ftp.is.co.za/rfc/rfc1808.txt'), 'ftp://ftp.is.co.za/rfc/rfc1808.txt');
t.ok(is_uri('ftp://ftp.is.co.za/../../../rfc/rfc1808.txt'), 'ftp://ftp.is.co.za/../../../rfc/rfc1808.txt');
t.ok(is_uri('http://www.ietf.org/rfc/rfc2396.txt'), 'http://www.ietf.org/rfc/rfc2396.txt');
t.ok(is_uri('ldap://[2001:db8::7]/c=GB?objectClass?one'), 'ldap://[2001:db8::7]/c=GB?objectClass?one');
t.ok(is_uri('mailto:John.Doe@example.com'), 'mailto:John.Doe@example.com');
t.ok(is_uri('news:comp.infosystems.www.servers.unix'), 'news:comp.infosystems.www.servers.unix');
t.ok(is_uri('tel:+1-816-555-1212'), 'tel:+1-816-555-1212');
t.ok(is_uri('telnet://192.0.2.16:80/'), 'telnet://192.0.2.16:80/');
t.ok(is_uri('urn:oasis:names:specification:docbook:dtd:xml:4.1.2'), 'urn:oasis:names:specification:docbook:dtd:xml:4.1.2');
// invalid
t.notOk(is_uri(''), "bad: ''");
t.notOk(is_uri('foo'), 'bad: foo');
t.notOk(is_uri('foo@bar'), 'bad: foo@bar');
t.notOk(is_uri('http://<foo>'), 'bad: http://<foo>'); // illegal characters
t.notOk(is_uri('://bob/'), 'bad: ://bob/'); // empty schema
t.notOk(is_uri('1http://bob'), 'bad: 1http://bob/'); // bad schema
t.notOk(is_uri('1http:////foo.html'), 'bad: 1http://bob/'); // bad path
t.notOk(is_uri('http://example.w3.org/%illegal.html'), 'http://example.w3.org/%illegal.html');
t.notOk(is_uri('http://example.w3.org/%a'), 'http://example.w3.org/%a'); // partial escape
t.notOk(is_uri('http://example.w3.org/%a/foo'), 'http://example.w3.org/%a/foo'); // partial escape
t.notOk(is_uri('http://example.w3.org/%at'), 'http://example.w3.org/%at'); // partial escape
t.end();
});

28
node_modules/valid-url/test/is_web_uri.js generated vendored Normal file
View File

@ -0,0 +1,28 @@
var test = require("tap").test,
is_web_uri = require('../').is_web_uri;
test("testing is_web_uri", function (t) {
// valid
t.ok(is_web_uri('https://www.richardsonnen.com/'), 'https://www.richardsonnen.com/');
t.ok(is_web_uri('https://www.richardsonnen.com'), 'https://www.richardsonnen.com');
t.ok(is_web_uri('https://www.richardsonnen.com/foo/bar/test.html'), 'https://www.richardsonnen.com/foo/bar/test.html');
t.ok(is_web_uri('https://www.richardsonnen.com/?foo=bar'), 'https://www.richardsonnen.com/?foo=bar');
t.ok(is_web_uri('https://www.richardsonnen.com:8080/test.html'), 'https://www.richardsonnen.com:8080/test.html');
t.ok(is_web_uri('http://www.richardsonnen.com/'), 'http://www.richardsonnen.com/');
t.ok(is_web_uri('http://www.richardsonnen.com'), 'http://www.richardsonnen.com');
t.ok(is_web_uri('http://www.richardsonnen.com/foo/bar/test.html'), 'http://www.richardsonnen.com/foo/bar/test.html');
t.ok(is_web_uri('http://www.richardsonnen.com/?foo=bar'), 'http://www.richardsonnen.com/?foo=bar');
t.ok(is_web_uri('http://www.richardsonnen.com:8080/test.html'), 'http://www.richardsonnen.com:8080/test.html');
t.ok(is_web_uri('http://example.w3.org/path%20with%20spaces.html'), 'http://example.w3.org/path%20with%20spaces.html');
t.ok(is_web_uri('http://192.168.0.1/'), 'http://192.168.0.1/');
// invalid
t.ok(!is_web_uri(''), "bad: ''");
t.ok(!is_web_uri('ftp://ftp.richardsonnen.com'), "bad: 'ftp://ftp.richardsonnen.com'");
t.ok(!is_web_uri('https:www.richardsonnen.com'), "bad: 'http:www.richardsonnen.com'");
t.ok(!is_web_uri('http:www.richardsonnen.com'), "bad: 'http:www.richardsonnen.com'");
t.end();
});

84
package-lock.json generated
View File

@ -9,13 +9,20 @@
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"@7c/validurl": "^0.0.3",
"@mozilla/readability": "^0.3.0",
"express": "^4.17.1",
"express-rate-limit": "^6.0.5",
"jsdom": "^16.4.0",
"turndown": "^7.0.0"
},
"devDependencies": {}
"turndown": "^7.0.0",
"url": "^0.11.0",
"valid-url": "^1.0.9"
}
},
"node_modules/@7c/validurl": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/@7c/validurl/-/validurl-0.0.3.tgz",
"integrity": "sha512-hmy54tf9ANyD2Iy0F6w0tF+jLwMDvpUWRD+jsSppinIINsre74IOlU79M6BdZLdcFoz9CNDVX6XofOT7O5ne8w=="
},
"node_modules/@mozilla/readability": {
"version": "0.3.0",
@ -420,9 +427,9 @@
}
},
"node_modules/express-rate-limit": {
"version": "6.0.5",
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-6.0.5.tgz",
"integrity": "sha512-EB1mRTrzyyPfEsQZIQFXocd8NKZoDZbEwrtbdgkc20Yed6oYg02Xfjza2HHPI/0orp54BrFeHeT92ICB9ydokw==",
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-6.1.0.tgz",
"integrity": "sha512-OWyJUDYVq/hRxGU3ufTnXDer5bRBwFiq5D35ZSZ9B2EHdjulWO4bwrbg+iIrapodDZse/35obeOj7igRHuP3Zw==",
"engines": {
"node": ">= 14.5.0"
},
@ -823,6 +830,15 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/querystring": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz",
"integrity": "sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA=",
"deprecated": "The querystring API is considered Legacy. new code should use the URLSearchParams API instead.",
"engines": {
"node": ">=0.4.x"
}
},
"node_modules/range-parser": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
@ -1028,6 +1044,20 @@
"node": ">= 0.8"
}
},
"node_modules/url": {
"version": "0.11.0",
"resolved": "https://registry.npmjs.org/url/-/url-0.11.0.tgz",
"integrity": "sha1-ODjpfPxgUh63PFJajlW/3Z4uKPE=",
"dependencies": {
"punycode": "1.3.2",
"querystring": "0.2.0"
}
},
"node_modules/url/node_modules/punycode": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.3.2.tgz",
"integrity": "sha1-llOgNvt8HuQjQvIyXM7v6jkmxI0="
},
"node_modules/utils-merge": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
@ -1036,6 +1066,11 @@
"node": ">= 0.4.0"
}
},
"node_modules/valid-url": {
"version": "1.0.9",
"resolved": "https://registry.npmjs.org/valid-url/-/valid-url-1.0.9.tgz",
"integrity": "sha1-HBRHm0DxOXp1eC8RXkCGRHQzogA="
},
"node_modules/vary": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
@ -1137,6 +1172,11 @@
}
},
"dependencies": {
"@7c/validurl": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/@7c/validurl/-/validurl-0.0.3.tgz",
"integrity": "sha512-hmy54tf9ANyD2Iy0F6w0tF+jLwMDvpUWRD+jsSppinIINsre74IOlU79M6BdZLdcFoz9CNDVX6XofOT7O5ne8w=="
},
"@mozilla/readability": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/@mozilla/readability/-/readability-0.3.0.tgz",
@ -1446,9 +1486,9 @@
}
},
"express-rate-limit": {
"version": "6.0.5",
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-6.0.5.tgz",
"integrity": "sha512-EB1mRTrzyyPfEsQZIQFXocd8NKZoDZbEwrtbdgkc20Yed6oYg02Xfjza2HHPI/0orp54BrFeHeT92ICB9ydokw==",
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-6.1.0.tgz",
"integrity": "sha512-OWyJUDYVq/hRxGU3ufTnXDer5bRBwFiq5D35ZSZ9B2EHdjulWO4bwrbg+iIrapodDZse/35obeOj7igRHuP3Zw==",
"requires": {}
},
"fast-levenshtein": {
@ -1743,6 +1783,11 @@
"resolved": "https://registry.npmjs.org/qs/-/qs-6.9.6.tgz",
"integrity": "sha512-TIRk4aqYLNoJUbd+g2lEdz5kLWIuTMRagAXxl78Q0RiVjAOugHmeKNGdd3cwo/ktpf9aL9epCfFqWDEKysUlLQ=="
},
"querystring": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz",
"integrity": "sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA="
},
"range-parser": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
@ -1894,11 +1939,32 @@
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
"integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw="
},
"url": {
"version": "0.11.0",
"resolved": "https://registry.npmjs.org/url/-/url-0.11.0.tgz",
"integrity": "sha1-ODjpfPxgUh63PFJajlW/3Z4uKPE=",
"requires": {
"punycode": "1.3.2",
"querystring": "0.2.0"
},
"dependencies": {
"punycode": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.3.2.tgz",
"integrity": "sha1-llOgNvt8HuQjQvIyXM7v6jkmxI0="
}
}
},
"utils-merge": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
"integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM="
},
"valid-url": {
"version": "1.0.9",
"resolved": "https://registry.npmjs.org/valid-url/-/valid-url-1.0.9.tgz",
"integrity": "sha1-HBRHm0DxOXp1eC8RXkCGRHQzogA="
},
"vary": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",

View File

@ -4,11 +4,13 @@
"description": "",
"main": "index.js",
"dependencies": {
"@7c/validurl": "^0.0.3",
"@mozilla/readability": "^0.3.0",
"express": "^4.17.1",
"express-rate-limit": "^6.0.5",
"jsdom": "^16.4.0",
"turndown": "^7.0.0"
"turndown": "^7.0.0",
"url": "^0.11.0"
},
"scripts": {
"start": "node index.js"

View File

@ -3,6 +3,12 @@ var urlparser = require('url');
module.exports = {
list: [
{
domain: /.*/,
remove: [
/\[¶\]\(#[^\s]+\s+"[^"]+"\)/g
]
},
{
domain: /.*\.wikipedia\.org/,
remove: [
@ -12,7 +18,7 @@ module.exports = {
],
filter: function (url, data) {
let domain = urlparser.parse(url).hostname
let domain = urlparser.parse(url).hostname
for (let i=0;i<this.list.length;i++) {
if (domain.match(this.list[i].domain)) {
for (let j=0;j<this.list[i].remove.length; j++) {