encodeurl 1.0.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -34
- package/index.js +1 -1
- package/package.json +9 -7
- package/HISTORY.md +0 -9
package/README.md
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Encode URL
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[![NPM Downloads][downloads-image]][downloads-url]
|
|
5
|
-
[![Node.js Version][node-version-image]][node-version-url]
|
|
6
|
-
[![Build Status][travis-image]][travis-url]
|
|
7
|
-
[![Test Coverage][coveralls-image]][coveralls-url]
|
|
8
|
-
|
|
9
|
-
Encode a URL to a percent-encoded form, excluding already-encoded sequences
|
|
3
|
+
Encode a URL to a percent-encoded form, excluding already-encoded sequences.
|
|
10
4
|
|
|
11
5
|
## Installation
|
|
12
6
|
|
|
13
7
|
```sh
|
|
14
|
-
|
|
8
|
+
npm install encodeurl
|
|
15
9
|
```
|
|
16
10
|
|
|
17
11
|
## API
|
|
@@ -24,24 +18,13 @@ var encodeUrl = require('encodeurl')
|
|
|
24
18
|
|
|
25
19
|
Encode a URL to a percent-encoded form, excluding already-encoded sequences.
|
|
26
20
|
|
|
27
|
-
This function
|
|
28
|
-
code points (as UTF-8 byte sequences). This function will not encode the
|
|
29
|
-
"%" character unless it is not part of a valid sequence (`%20` will be
|
|
30
|
-
left as-is, but `%foo` will be encoded as `%25foo`).
|
|
31
|
-
|
|
32
|
-
This encode is meant to be "safe" and does not throw errors. It will try as
|
|
33
|
-
hard as it can to properly encode the given URL, including replacing any raw,
|
|
34
|
-
unpaired surrogate pairs with the Unicode replacement character prior to
|
|
35
|
-
encoding.
|
|
21
|
+
This function accepts a URL and encodes all the non-URL code points (as UTF-8 byte sequences). It will not encode the "%" character unless it is not part of a valid sequence (`%20` will be left as-is, but `%foo` will be encoded as `%25foo`).
|
|
36
22
|
|
|
37
|
-
This
|
|
38
|
-
will not encode the `%` character if that is part of a valid sequence, will
|
|
39
|
-
not encode `[` and `]` (for IPv6 hostnames) and will replace raw, unpaired
|
|
40
|
-
surrogate pairs with the Unicode replacement character (instead of throwing).
|
|
23
|
+
This encode is meant to be "safe" and does not throw errors. It will try as hard as it can to properly encode the given URL, including replacing any raw, unpaired surrogate pairs with the Unicode replacement character prior to encoding.
|
|
41
24
|
|
|
42
25
|
## Examples
|
|
43
26
|
|
|
44
|
-
### Encode a URL containing user-
|
|
27
|
+
### Encode a URL containing user-controlled data
|
|
45
28
|
|
|
46
29
|
```js
|
|
47
30
|
var encodeUrl = require('encodeurl')
|
|
@@ -93,6 +76,19 @@ http.createServer(function onRequest (req, res) {
|
|
|
93
76
|
})
|
|
94
77
|
```
|
|
95
78
|
|
|
79
|
+
## Similarities
|
|
80
|
+
|
|
81
|
+
This function is _similar_ to the intrinsic function `encodeURI`. However, it will not encode:
|
|
82
|
+
|
|
83
|
+
* The `\`, `^`, or `|` characters
|
|
84
|
+
* The `%` character when it's part of a valid sequence
|
|
85
|
+
* `[` and `]` (for IPv6 hostnames)
|
|
86
|
+
* Replaces raw, unpaired surrogate pairs with the Unicode replacement character
|
|
87
|
+
|
|
88
|
+
As a result, the encoding aligns closely with the behavior in the [WHATWG URL specification][whatwg-url]. However, this package only encodes strings and does not do any URL parsing or formatting.
|
|
89
|
+
|
|
90
|
+
It is expected that any output from `new URL(url)` will not change when used with this package, as the output has already been encoded. Additionally, if we were to encode before `new URL(url)`, we do not expect the before and after encoded formats to be parsed any differently.
|
|
91
|
+
|
|
96
92
|
## Testing
|
|
97
93
|
|
|
98
94
|
```sh
|
|
@@ -111,14 +107,3 @@ $ npm run lint
|
|
|
111
107
|
## License
|
|
112
108
|
|
|
113
109
|
[MIT](LICENSE)
|
|
114
|
-
|
|
115
|
-
[npm-image]: https://img.shields.io/npm/v/encodeurl.svg
|
|
116
|
-
[npm-url]: https://npmjs.org/package/encodeurl
|
|
117
|
-
[node-version-image]: https://img.shields.io/node/v/encodeurl.svg
|
|
118
|
-
[node-version-url]: https://nodejs.org/en/download
|
|
119
|
-
[travis-image]: https://img.shields.io/travis/pillarjs/encodeurl.svg
|
|
120
|
-
[travis-url]: https://travis-ci.org/pillarjs/encodeurl
|
|
121
|
-
[coveralls-image]: https://img.shields.io/coveralls/pillarjs/encodeurl.svg
|
|
122
|
-
[coveralls-url]: https://coveralls.io/r/pillarjs/encodeurl?branch=master
|
|
123
|
-
[downloads-image]: https://img.shields.io/npm/dm/encodeurl.svg
|
|
124
|
-
[downloads-url]: https://npmjs.org/package/encodeurl
|
package/index.js
CHANGED
|
@@ -19,7 +19,7 @@ module.exports = encodeUrl
|
|
|
19
19
|
* @private
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
var ENCODE_CHARS_REGEXP = /(?:[^\x21\
|
|
22
|
+
var ENCODE_CHARS_REGEXP = /(?:[^\x21\x23-\x3B\x3D\x3F-\x5F\x61-\x7A\x7C\x7E]|%(?:[^0-9A-Fa-f]|[0-9A-Fa-f][^0-9A-Fa-f]|$))+/g
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* RegExp to match unmatched surrogate pair.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "encodeurl",
|
|
3
3
|
"description": "Encode a URL to a percent-encoded form, excluding already-encoded sequences",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Douglas Christopher Wilson <doug@somethingdoug.com>"
|
|
7
7
|
],
|
|
@@ -13,11 +13,13 @@
|
|
|
13
13
|
],
|
|
14
14
|
"repository": "pillarjs/encodeurl",
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"eslint": "
|
|
17
|
-
"eslint-config-standard": "
|
|
18
|
-
"eslint-plugin-
|
|
19
|
-
"eslint-plugin-
|
|
20
|
-
"
|
|
16
|
+
"eslint": "5.11.1",
|
|
17
|
+
"eslint-config-standard": "12.0.0",
|
|
18
|
+
"eslint-plugin-import": "2.14.0",
|
|
19
|
+
"eslint-plugin-node": "7.0.1",
|
|
20
|
+
"eslint-plugin-promise": "4.0.1",
|
|
21
|
+
"eslint-plugin-standard": "4.0.0",
|
|
22
|
+
"istanbul": "0.4.5",
|
|
21
23
|
"mocha": "2.5.3"
|
|
22
24
|
},
|
|
23
25
|
"files": [
|
|
@@ -30,7 +32,7 @@
|
|
|
30
32
|
"node": ">= 0.8"
|
|
31
33
|
},
|
|
32
34
|
"scripts": {
|
|
33
|
-
"lint": "eslint
|
|
35
|
+
"lint": "eslint .",
|
|
34
36
|
"test": "mocha --reporter spec --bail --check-leaks test/",
|
|
35
37
|
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
|
|
36
38
|
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
|