Skip to content

Commit 40be69b

Browse files
committed
feat: throw error for invalid remotes
1 parent 64f2bdb commit 40be69b

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

lib/util/extractUrlAndGlobal.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111
*/
1212
module.exports = function extractUrlAndGlobal(urlAndGlobal) {
1313
const index = urlAndGlobal.indexOf("@");
14+
if (index <= 0 || index === urlAndGlobal.length - 1) {
15+
throw new Error(`Invalid request "${urlAndGlobal}"`);
16+
}
1417
return [urlAndGlobal.substring(index + 1), urlAndGlobal.substring(0, index)];
1518
};

test/extractUrlAndGlobal.unittest.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,15 @@ describe("extractUrlAndGlobal", () => {
2121
"_"
2222
]);
2323
});
24+
it("should throw error if starts with @", () => {
25+
expect(() => extractUrlAndGlobal("@something")).toThrow();
26+
});
27+
28+
it("should throw error if ends with @", () => {
29+
expect(() => extractUrlAndGlobal("something@")).toThrow();
30+
});
31+
32+
it("should throw error if do not have @", () => {
33+
expect(() => extractUrlAndGlobal("something")).toThrow();
34+
});
2435
});

0 commit comments

Comments
 (0)