mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-06 11:36:58 +03:00
throw error 400 when start or endtime has colon
This commit is contained in:
@@ -324,6 +324,15 @@ function checkInvalidFields(videoID: any, userID: any, segments: Array<any>): Ch
|
|||||||
if (!Array.isArray(segments) || segments.length < 1) {
|
if (!Array.isArray(segments) || segments.length < 1) {
|
||||||
invalidFields.push("segments");
|
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) {
|
if (invalidFields.length !== 0) {
|
||||||
// invalid request
|
// invalid request
|
||||||
|
|||||||
@@ -987,4 +987,26 @@ describe("postSkipSegments", () => {
|
|||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.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));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user