throw error 400 when start or endtime has colon

This commit is contained in:
Michael C 2021-08-24 19:12:58 -04:00
parent 954ac1eb07
commit c3f7b29d44
No known key found for this signature in database
GPG key ID: FFB04FB3B878B7B4
2 changed files with 31 additions and 0 deletions

View file

@ -324,6 +324,15 @@ function checkInvalidFields(videoID: any, userID: any, segments: Array<any>): Ch
if (!Array.isArray(segments) || segments.length < 1) {
invalidFields.push("segments");
}
// validate start and end times (no : marks)
for (const segmentPair of segments) {
const startTime = segmentPair.segment[0];
const endTime = segmentPair.segment[1];
if ((typeof startTime === "string" && startTime.includes(":")) ||
(typeof endTime === "string" && endTime.includes(":"))) {
invalidFields.push("segment time");
}
}
if (invalidFields.length !== 0) {
// invalid request

View file

@ -987,4 +987,26 @@ describe("postSkipSegments", () => {
})
.catch(err => done(err));
});
it("Should not be able to submit with colons in timestamps", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest",
videoID: "colon-1",
segments: [{
segment: ["0:2.000", "3:10.392"],
category: "sponsor",
}]
}),
})
.then(async res => {
assert.strictEqual(res.status, 400);
done();
})
.catch(err => done(err));
});
});