+20
-17
| 'use strict'; | ||
| var parse = require('url-parse'); | ||
| var required = require('requires-port') | ||
| , parse = require('url-parse'); | ||
@@ -20,24 +21,26 @@ /** | ||
| // | ||
| if (!/^(http|ws|file)s?/.test(url)) url = 'http://'+ url; | ||
| url = parse(url); | ||
| if (!/^(http|ws|file)s?/i.test(url)) url = 'http://'+ url; | ||
| url = parse(url.toLowerCase()); | ||
| } | ||
| var noport | ||
| , protocol = url.protocol | ||
| , port = url.port && +url.port; | ||
| // | ||
| // 6.2. ASCII Serialization of an Origin | ||
| // http://tools.ietf.org/html/rfc6454#section-6.2 | ||
| // | ||
| // @TODO If we cannot generate a proper origin from the url because | ||
| // origin/host/port information is missing we should return the string `null` | ||
| // | ||
| var protocol = url.protocol | ||
| , port = url.port && +url.port | ||
| , noport = !required(port, protocol); | ||
| // | ||
| // Origins should not include the default port number: | ||
| // 4. Origin of a URI | ||
| // http://tools.ietf.org/html/rfc6454#section-4 | ||
| // | ||
| // @see https://url.spec.whatwg.org/#default-port | ||
| // @see https://url.spec.whatwg.org/#origin | ||
| // States that url.scheme, host should be converted to lower case. This also | ||
| // makes it easier to match origins as everything is just lower case. | ||
| // | ||
| if ( | ||
| !port | ||
| || 'file:' === protocol | ||
| || (80 === port && ('http:' === protocol || 'ws:' === protocol )) | ||
| || (443 === port && ('https:' === protocol || 'wss:' === protocol)) | ||
| ) noport = true; | ||
| return url.protocol +'//'+ url.hostname + (noport ? '' : ':'+ port); | ||
| return (url.protocol +'//'+ url.hostname + (noport ? '' : ':'+ port)).toLowerCase(); | ||
| } | ||
@@ -44,0 +47,0 @@ |
+4
-3
| { | ||
| "name": "original", | ||
| "version": "0.0.5", | ||
| "version": "0.0.6", | ||
| "description": "Generate the origin from an URL or check if two URL/Origins are the same", | ||
@@ -23,3 +23,4 @@ "main": "index.js", | ||
| "dependencies": { | ||
| "url-parse": "0.0.x" | ||
| "requires-port": "0.0.x", | ||
| "url-parse": "0.1.x" | ||
| }, | ||
@@ -29,5 +30,5 @@ "devDependencies": { | ||
| "istanbul": "0.3.x", | ||
| "mocha": "1.21.x", | ||
| "mocha": "2.0.x", | ||
| "pre-commit": "0.0.x" | ||
| } | ||
| } |
+1
-3
| # origin(al) | ||
| [](https://travis-ci.org/unshiftio/original) | ||
| [](http://badge.fury.io/js/original) | ||
| [](https://coveralls.io/r/unshiftio/original?branch=master) | ||
| [](http://unshift.io)[](http://browsenpm.org/package/original)[](https://travis-ci.org/unshiftio/original)[](https://david-dm.org/unshiftio/original)[](https://coveralls.io/r/unshiftio/original?branch=master)[](http://webchat.freenode.net/?channels=unshift) | ||
@@ -7,0 +5,0 @@ Original generates the origin URL for a given URL or URL object. In addition to |
+12
-0
@@ -24,2 +24,14 @@ describe('original', function () { | ||
| it('lowercases the origin', function () { | ||
| var o = origin('hTtp://WwW.ExAMPLE.cOM:8080'); | ||
| assume(o).equals('http://www.example.com:8080'); | ||
| o = origin('https://www.EXAMPLE.com:8080'); | ||
| assume(o).equals('https://www.example.com:8080'); | ||
| o = origin('HTTPS://WWW.example.COM:8080'); | ||
| assume(o).equals('https://www.example.com:8080'); | ||
| }); | ||
| it('also accepts missing protocols', function () { | ||
@@ -26,0 +38,0 @@ var o = origin('www.example.com'); |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
7124
17.77%117
10.38%2
100%52
-3.7%+ Added
+ Added
+ Added
+ Added
- Removed
Updated