Skip to content

Commit

Permalink
fix: invalid regular expression in safari
Browse files Browse the repository at this point in the history
fix #108
  • Loading branch information
buqiyuan committed Jul 26, 2022
1 parent 31cbd31 commit 6375f53
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/utils/request.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios from 'axios';
import { message as $message } from 'ant-design-vue';
import { uniqueSlash } from './urlUtils';
import type { AxiosRequestConfig } from 'axios';
import { ACCESS_TOKEN_KEY } from '@/enums/cacheEnum';
import { Storage } from '@/utils/Storage';
Expand Down Expand Up @@ -113,7 +114,7 @@ export const request = async <T = any>(
return $message.error('你没有访问该接口的权限,请联系管理员!');
}
const fullUrl = `${(isMock ? baseMockUrl : baseApiUrl) + config.url}`;
config.url = fullUrl.replace(/(?<!:)\/{2,}/g, '/');
config.url = uniqueSlash(fullUrl);
// if (IS_PROD) {
// // 保持api请求的协议与当前访问的站点协议一致
// config.url.replace(/^https?:/g, location.protocol);
Expand Down
4 changes: 3 additions & 1 deletion src/utils/urlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ export function setObjToUrlParams(baseUrl: string, obj: object): string {
* @param path 要处理的路径
* @returns {string} 将/去重后的结果
*/
export const uniqueSlash = (path: string) => path.replace(/(?<!:)\/{2,}/g, '/');
export const uniqueSlash = (path: string) => path.replace(/(https?:\/)|(\/)+/g, '$1$2');
// Safari 不支持以下正则(反向否定查找) shit!
// export const uniqueSlash = (path: string) => path.replace(/(?<!:)\/{2,}/g, '/');

1 comment on commit 6375f53

@vercel
Copy link

@vercel vercel bot commented on 6375f53 Jul 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

vue3-antd-admin – ./

vue3-antd-admin.vercel.app
vue3-antd-admin-git-main-buqiyuan.vercel.app
vue3-antd-admin-buqiyuan.vercel.app

Please sign in to comment.