Skip to content

Commit

Permalink
Merge pull request #14781 from tanhauhau/tanhauhau/add-validation-to-…
Browse files Browse the repository at this point in the history
…remotes

feat: add validation to remotes
  • Loading branch information
sokra committed Nov 29, 2021
2 parents bb51f18 + 40be69b commit a7bba26
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/util/extractUrlAndGlobal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
};
11 changes: 11 additions & 0 deletions test/extractUrlAndGlobal.unittest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

0 comments on commit a7bba26

Please sign in to comment.