twikoo-func 1.6.13 → 1.6.14

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/package.json +1 -1
  2. package/utils/index.js +6 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "twikoo-func",
3
- "version": "1.6.13",
3
+ "version": "1.6.14",
4
4
  "description": "A simple comment system.",
5
5
  "author": "imaegoo <hello@imaegoo.com> (https://github.com/imaegoo)",
6
6
  "license": "MIT",
package/utils/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ const { URL } = require('url')
1
2
  const { axios, bowser, ipToRegion, md5 } = require('./lib')
2
3
  const { RES_CODE } = require('./constants')
3
4
  const ipRegionSearcher = ipToRegion.create() // 初始化 IP 属地
@@ -110,11 +111,12 @@ const fn = {
110
111
  return comments
111
112
  },
112
113
  getRelativeUrl (url) {
113
- let x = url.indexOf('/')
114
- for (let i = 0; i < 2; i++) {
115
- x = url.indexOf('/', x + 1)
114
+ try {
115
+ return (new URL(url)).pathname
116
+ } catch (e) {
117
+ // 如果 url 已经是一个相对地址了,会报 ERR_INVALID_URL,返回原始 url 就行
118
+ return url
116
119
  }
117
- return url.substring(x)
118
120
  },
119
121
  getMailMd5 (comment) {
120
122
  if (comment.mailMd5) {