normalize-url 4.4.1 → 4.5.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.
Files changed (2) hide show
  1. package/index.js +11 -3
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -2,6 +2,10 @@
2
2
  // TODO: Use the `URL` global when targeting Node.js 10
3
3
  const URLParser = typeof URL === 'undefined' ? require('url').URL : URL;
4
4
 
5
+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
6
+ const DATA_URL_DEFAULT_MIME_TYPE = 'text/plain';
7
+ const DATA_URL_DEFAULT_CHARSET = 'us-ascii';
8
+
5
9
  const testParameter = (name, filters) => {
6
10
  return filters.some(filter => filter instanceof RegExp ? filter.test(name) : filter === name);
7
11
  };
@@ -27,17 +31,21 @@ const normalizeDataURL = (urlString, {stripHash}) => {
27
31
  // Lowercase MIME type
28
32
  const mimeType = (mediaType.shift() || '').toLowerCase();
29
33
  const attributes = mediaType
30
- .filter(Boolean)
31
34
  .map(attribute => {
32
35
  let [key, value = ''] = attribute.split('=').map(string => string.trim());
33
36
 
34
37
  // Lowercase `charset`
35
38
  if (key === 'charset') {
36
39
  value = value.toLowerCase();
40
+
41
+ if (value === DATA_URL_DEFAULT_CHARSET) {
42
+ return '';
43
+ }
37
44
  }
38
45
 
39
46
  return `${key}${value ? `=${value}` : ''}`;
40
- });
47
+ })
48
+ .filter(Boolean);
41
49
 
42
50
  const normalizedMediaType = [
43
51
  ...attributes
@@ -47,7 +55,7 @@ const normalizeDataURL = (urlString, {stripHash}) => {
47
55
  normalizedMediaType.push('base64');
48
56
  }
49
57
 
50
- if (normalizedMediaType.length !== 0 || mimeType) {
58
+ if (normalizedMediaType.length !== 0 || (mimeType && mimeType !== DATA_URL_DEFAULT_MIME_TYPE)) {
51
59
  normalizedMediaType.unshift(mimeType);
52
60
  }
53
61
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "normalize-url",
3
- "version": "4.4.1",
3
+ "version": "4.5.0",
4
4
  "description": "Normalize a URL",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/normalize-url",