Fix #1409, slug cannot be empty

pull/1414/head
Louis Lam 3 years ago
parent 6c7a0ff7d3
commit 28d72fcd08

@ -218,6 +218,10 @@ class Database {
* @returns {Promise<void>}
*/
static async migrateNewStatusPage() {
// Fix 1.13.0 empty slug bug
await R.exec("UPDATE status_page SET slug = 'empty-slug-recover' WHERE TRIM(slug) = ''");
let title = await setting("title");
if (title) {

@ -90,6 +90,8 @@ module.exports.statusPageSocketHandler = (socket) => {
socket.on("saveStatusPage", async (slug, config, imgDataUrl, publicGroupList, callback) => {
try {
checkSlug(config.slug);
checkLogin(socket);
apicache.clear();
@ -227,11 +229,7 @@ module.exports.statusPageSocketHandler = (socket) => {
// lower case only
slug = slug.toLowerCase();
// Check slug a-z, 0-9, - only
// Regex from: https://stackoverflow.com/questions/22454258/js-regex-string-validation-for-slug
if (!slug.match(/^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$/)) {
throw new Error("Invalid Slug");
}
checkSlug(slug);
let statusPage = R.dispense("status_page");
statusPage.slug = slug;
@ -302,3 +300,23 @@ module.exports.statusPageSocketHandler = (socket) => {
}
});
};
/**
* Check slug a-z, 0-9, - only
* Regex from: https://stackoverflow.com/questions/22454258/js-regex-string-validation-for-slug
*/
function checkSlug(slug) {
if (typeof slug !== "string") {
throw new Error("Slug must be string");
}
slug = slug.trim();
if (!slug) {
throw new Error("Slug cannot be empty");
}
if (!slug.match(/^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$/)) {
throw new Error("Invalid Slug");
}
}

@ -518,6 +518,7 @@ export default {
save() {
let startTime = new Date();
this.config.slug = this.config.slug.trim().toLowerCase();
this.$root.getSocket().emit("saveStatusPage", this.slug, this.config, this.imgDataUrl, this.$root.publicGroupList, (res) => {
if (res.ok) {

Loading…
Cancel
Save