Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Nov 9, 2023
1 parent 8d86e0d commit f4405b6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/contrib/parseuri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ const parts = [
'source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'
];

export function parse(str) {
export function parse(str: string) {
if (str.length > 2000) {
throw "URI too long";
}

const src = str,
b = str.indexOf('['),
e = str.indexOf(']');
Expand Down
3 changes: 3 additions & 0 deletions test/parseuri.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// imported from https://github.com/galkn/parseuri
const expect = require("expect.js");
const parseuri = require("..").parse;
const { repeat } = require("./util");

describe("parseuri", function () {
it("should parse an uri", function () {
Expand Down Expand Up @@ -64,5 +65,7 @@ describe("parseuri", function () {
expect(relativeWithQuery.host).to.be("");
expect(relativeWithQuery.path).to.be("/foo");
expect(relativeWithQuery.query).to.be("bar=@example.com");

expect(() => parseuri(repeat("a", 2001))).to.throwError("URI too long");
});
});

0 comments on commit f4405b6

Please sign in to comment.