feat: throw error for invalid remotes

This commit is contained in:
tanhauhau 2021-11-28 18:08:25 +08:00
parent 64f2bdb7a9
commit 40be69b50a
2 changed files with 14 additions and 0 deletions

View File

@ -11,5 +11,8 @@
*/
module.exports = function extractUrlAndGlobal(urlAndGlobal) {
const index = urlAndGlobal.indexOf("@");
if (index <= 0 || index === urlAndGlobal.length - 1) {
throw new Error(`Invalid request "${urlAndGlobal}"`);
}
return [urlAndGlobal.substring(index + 1), urlAndGlobal.substring(0, index)];
};

View File

@ -21,4 +21,15 @@ describe("extractUrlAndGlobal", () => {
"_"
]);
});
it("should throw error if starts with @", () => {
expect(() => extractUrlAndGlobal("@something")).toThrow();
});
it("should throw error if ends with @", () => {
expect(() => extractUrlAndGlobal("something@")).toThrow();
});
it("should throw error if do not have @", () => {
expect(() => extractUrlAndGlobal("something")).toThrow();
});
});