Skip to content

Commit

Permalink
Merge pull request #268 from NodeSecure/avoid-invalid-github-crash
Browse files Browse the repository at this point in the history
Avoid invalid GitHub crash
  • Loading branch information
fraxken authored Nov 28, 2023
2 parents 618033a + 198e0d6 commit c61aff9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
3 changes: 3 additions & 0 deletions public/js/components/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export class HomeView {
const repoName = utils.getGithubRepositoryPath(
utils.parseRepositoryUrl(repository)
)
if (repoName === null) {
return;
}

fetchScorecardData(repoName).then((data) => {
if (data !== null) {
Expand Down
3 changes: 3 additions & 0 deletions public/js/components/package/pannels/scorecard.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export class Scorecard {
}

const repoName = utils.getGithubRepositoryPath(githubURL.href);
if (repoName === null) {
return;
}
const pannel = clone.getElementById("pan-scorecard");
fetchScorecardData(repoName).then((data) => {
if (!data) {
Expand Down
15 changes: 10 additions & 5 deletions public/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import avatarURL from "../img/avatar-default.png";
window.activeLegendElement = null;

export function getGithubRepositoryPath(url) {
const github = new URL(url);
try {
const github = new URL(url);

return github.pathname.slice(
1,
github.pathname.includes(".git") ? -4 : github.pathname.length
);
return github.pathname.slice(
1,
github.pathname.includes(".git") ? -4 : github.pathname.length
);
}
catch {
return null;
}
}

/**
Expand Down
15 changes: 13 additions & 2 deletions src/commands/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@ import path from "node:path";
// Import Internal Dependencies
import { buildServer } from "../http-server/index.js";

export async function start(json = "nsecure-result.json", options = {}) {
export async function start(
payloadFileBasename = "nsecure-result.json",
options = {}
) {
const port = Number(options.port);
const dataFilePath = path.join(process.cwd(), json);
const fileExtension = path.extname(payloadFileBasename);
if (fileExtension !== ".json" && fileExtension !== "") {
throw new Error("You must provide a JSON file (scanner payload) to open");
}

const dataFilePath = path.join(
process.cwd(),
fileExtension === "" ? `${payloadFileBasename}.json` : payloadFileBasename
);

const httpServer = buildServer(dataFilePath, {
port: Number.isNaN(port) ? 0 : port
Expand Down

0 comments on commit c61aff9

Please sign in to comment.