Skip to content

Commit

Permalink
Merge pull request #32 from ronyeh/master
Browse files Browse the repository at this point in the history
Use regex to check that the port is a series of digits 0-9.
  • Loading branch information
IonicaBizau authored Feb 2, 2022
2 parents 6098fcb + 95fd0c5 commit 5cef694
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ function parsePath(url) {
splits = output.resource.split(":");
if (splits.length === 2) {
output.resource = splits[0];
if (splits[1]) {
output.port = Number(splits[1]);
if (isNaN(output.port)) {
const port = splits[1];
if (port) {
output.port = Number(port);
if (isNaN(output.port) || port.match(/^\d+$/) === null) {
output.port = null;
parts.unshift(splits[1]);
parts.unshift(port);
}
} else {
output.port = null
Expand Down
12 changes: 12 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ const INPUTS = [
, hash: ""
, search: ""
}
], [
"git@github.com:0xABC/git-stats.git"
, {
protocols: []
, protocol: "ssh"
, port: null
, resource: "github.com"
, user: "git"
, pathname: "/0xABC/git-stats.git"
, hash: ""
, search: ""
}
], [
"https://attacker.com\\@example.com"
, {
Expand Down

0 comments on commit 5cef694

Please sign in to comment.