encodeurl 1.0.2 → 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 CHANGED
@@ -1,21 +1,11 @@
1
- # encodeurl
1
+ # Encode URL
2
2
 
3
- [![NPM Version][npm-image]][npm-url]
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
- This is a [Node.js](https://nodejs.org/en/) module available through the
14
- [npm registry](https://www.npmjs.com/). Installation is done using the
15
- [`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
16
-
17
7
  ```sh
18
- $ npm install encodeurl
8
+ npm install encodeurl
19
9
  ```
20
10
 
21
11
  ## API
@@ -28,24 +18,13 @@ var encodeUrl = require('encodeurl')
28
18
 
29
19
  Encode a URL to a percent-encoded form, excluding already-encoded sequences.
30
20
 
31
- This function will take an already-encoded URL and encode all the non-URL
32
- code points (as UTF-8 byte sequences). This function will not encode the
33
- "%" character unless it is not part of a valid sequence (`%20` will be
34
- left as-is, but `%foo` will be encoded as `%25foo`).
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`).
35
22
 
36
- This encode is meant to be "safe" and does not throw errors. It will try as
37
- hard as it can to properly encode the given URL, including replacing any raw,
38
- unpaired surrogate pairs with the Unicode replacement character prior to
39
- encoding.
40
-
41
- This function is _similar_ to the intrinsic function `encodeURI`, except it
42
- will not encode the `%` character if that is part of a valid sequence, will
43
- not encode `[` and `]` (for IPv6 hostnames) and will replace raw, unpaired
44
- 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.
45
24
 
46
25
  ## Examples
47
26
 
48
- ### Encode a URL containing user-controled data
27
+ ### Encode a URL containing user-controlled data
49
28
 
50
29
  ```js
51
30
  var encodeUrl = require('encodeurl')
@@ -97,6 +76,19 @@ http.createServer(function onRequest (req, res) {
97
76
  })
98
77
  ```
99
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
+
100
92
  ## Testing
101
93
 
102
94
  ```sh
@@ -115,14 +107,3 @@ $ npm run lint
115
107
  ## License
116
108
 
117
109
  [MIT](LICENSE)
118
-
119
- [npm-image]: https://img.shields.io/npm/v/encodeurl.svg
120
- [npm-url]: https://npmjs.org/package/encodeurl
121
- [node-version-image]: https://img.shields.io/node/v/encodeurl.svg
122
- [node-version-url]: https://nodejs.org/en/download
123
- [travis-image]: https://img.shields.io/travis/pillarjs/encodeurl.svg
124
- [travis-url]: https://travis-ci.org/pillarjs/encodeurl
125
- [coveralls-image]: https://img.shields.io/coveralls/pillarjs/encodeurl.svg
126
- [coveralls-url]: https://coveralls.io/r/pillarjs/encodeurl?branch=master
127
- [downloads-image]: https://img.shields.io/npm/dm/encodeurl.svg
128
- [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\x25\x26-\x3B\x3D\x3F-\x5B\x5D\x5F\x61-\x7A\x7E]|%(?:[^0-9A-Fa-f]|[0-9A-Fa-f][^0-9A-Fa-f]|$))+/g
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": "1.0.2",
4
+ "version": "2.0.0",
5
5
  "contributors": [
6
6
  "Douglas Christopher Wilson <doug@somethingdoug.com>"
7
7
  ],
@@ -13,12 +13,12 @@
13
13
  ],
14
14
  "repository": "pillarjs/encodeurl",
15
15
  "devDependencies": {
16
- "eslint": "3.19.0",
17
- "eslint-config-standard": "10.2.1",
18
- "eslint-plugin-import": "2.8.0",
19
- "eslint-plugin-node": "5.2.1",
20
- "eslint-plugin-promise": "3.6.0",
21
- "eslint-plugin-standard": "3.0.1",
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
22
  "istanbul": "0.4.5",
23
23
  "mocha": "2.5.3"
24
24
  },
package/HISTORY.md DELETED
@@ -1,14 +0,0 @@
1
- 1.0.2 / 2018-01-21
2
- ==================
3
-
4
- * Fix encoding `%` as last character
5
-
6
- 1.0.1 / 2016-06-09
7
- ==================
8
-
9
- * Fix encoding unpaired surrogates at start/end of string
10
-
11
- 1.0.0 / 2016-06-08
12
- ==================
13
-
14
- * Initial release