Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid invalid GitHub crash #268

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions public/js/components/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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
Loading