@alicloud/fetcher-jsonp 1.5.10-beta.0 → 1.5.10-beta.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.5.10-beta.1
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: JSONP 协议校验改用正则解析 scheme,不再依赖 new URL / Array.prototype.includes(兼容 IE11)
8
+
3
9
  ## 1.5.10-beta.0
4
10
 
5
11
  ### Patch Changes
@@ -9,16 +9,21 @@ var _const = require("../const");
9
9
  var _createError = _interopRequireDefault(require("./create-error"));
10
10
  var _generateCallbackName = _interopRequireDefault(require("./generate-callback-name"));
11
11
  var _clearCallbackFn = _interopRequireDefault(require("./clear-callback-fn"));
12
- var ALLOWED_PROTOCOLS = ['http:', 'https:'];
12
+ var REG_URL_SCHEME = /^([a-z][a-z0-9+.-]*):/i;
13
13
 
14
14
  /**
15
- * JSONP 本质是 <script src>,必须限制协议,禁止 data:/blob:/javascript: 等可执行任意代码的来源
15
+ * JSONP 本质是 <script src>,必须限制协议,禁止 data:/blob:/javascript: 等可执行任意代码的来源。
16
+ * 这里用正则解析 scheme,不依赖 new URL(IE11 无 URL 构造函数)。
16
17
  */
17
18
  function assertAllowedProtocol(url) {
18
- var _URL = new URL(url, window.location.href),
19
- protocol = _URL.protocol;
20
- if (!ALLOWED_PROTOCOLS.includes(protocol)) {
21
- throw (0, _createError.default)(_const.EJsonpError.INVALID_PROTOCOL, "JSONP url protocol is not allowed: ".concat(protocol));
19
+ var matched = url.trim().match(REG_URL_SCHEME);
20
+ if (!matched) {
21
+ // 相对路径或协议相对(//host),最终协议与当前页面一致
22
+ return;
23
+ }
24
+ var protocol = (matched[1] || '').toLowerCase();
25
+ if (protocol !== 'http' && protocol !== 'https') {
26
+ throw (0, _createError.default)(_const.EJsonpError.INVALID_PROTOCOL, "JSONP url protocol is not allowed: ".concat(protocol, ":"));
22
27
  }
23
28
  }
24
29
 
@@ -2,16 +2,21 @@ import { EJsonpError } from '../const';
2
2
  import createError from './create-error';
3
3
  import generateCallbackName from './generate-callback-name';
4
4
  import clearCallbackFn from './clear-callback-fn';
5
- var ALLOWED_PROTOCOLS = ['http:', 'https:'];
5
+ var REG_URL_SCHEME = /^([a-z][a-z0-9+.-]*):/i;
6
6
 
7
7
  /**
8
- * JSONP 本质是 <script src>,必须限制协议,禁止 data:/blob:/javascript: 等可执行任意代码的来源
8
+ * JSONP 本质是 <script src>,必须限制协议,禁止 data:/blob:/javascript: 等可执行任意代码的来源。
9
+ * 这里用正则解析 scheme,不依赖 new URL(IE11 无 URL 构造函数)。
9
10
  */
10
11
  function assertAllowedProtocol(url) {
11
- var _URL = new URL(url, window.location.href),
12
- protocol = _URL.protocol;
13
- if (!ALLOWED_PROTOCOLS.includes(protocol)) {
14
- throw createError(EJsonpError.INVALID_PROTOCOL, "JSONP url protocol is not allowed: ".concat(protocol));
12
+ var matched = url.trim().match(REG_URL_SCHEME);
13
+ if (!matched) {
14
+ // 相对路径或协议相对(//host),最终协议与当前页面一致
15
+ return;
16
+ }
17
+ var protocol = (matched[1] || '').toLowerCase();
18
+ if (protocol !== 'http' && protocol !== 'https') {
19
+ throw createError(EJsonpError.INVALID_PROTOCOL, "JSONP url protocol is not allowed: ".concat(protocol, ":"));
15
20
  }
16
21
  }
17
22
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alicloud/fetcher-jsonp",
3
- "version": "1.5.10-beta.0",
3
+ "version": "1.5.10-beta.1",
4
4
  "description": "fetcher 的底层 jsonp 实现,可独立使用",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,