fix: 修复 dynamicURL 错误匹配端口号
parent
30c3503b22
commit
7e29e91f0a
|
@ -1,4 +1,4 @@
|
||||||
const dynamicRE = /:([^/]+)/g;
|
const dynamicRE = /\/:([^/]+)/g;
|
||||||
export function dynamicURL(url: string, data: AnyObject = {}): string {
|
export function dynamicURL(url: string, data: AnyObject = {}): string {
|
||||||
return url.replace(dynamicRE, (_, $2) => data[$2]);
|
return url.replace(dynamicRE, (_, $2) => `/${data[$2]}`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,4 +19,17 @@ describe('src/helpers/dynamicURL.ts', () => {
|
||||||
}),
|
}),
|
||||||
).toBe('http://api.com/tests/name/axios/type/0/list');
|
).toBe('http://api.com/tests/name/axios/type/0/list');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('应该忽略端口号', () => {
|
||||||
|
expect(
|
||||||
|
dynamicURL(':8080/:id', {
|
||||||
|
id: 0,
|
||||||
|
}),
|
||||||
|
).toBe(':8080/0');
|
||||||
|
expect(
|
||||||
|
dynamicURL('http://api.com:8080/:id', {
|
||||||
|
id: 0,
|
||||||
|
}),
|
||||||
|
).toBe('http://api.com:8080/0');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue