New option to make pad names case-insensitive

fixes #3844
This commit is contained in:
DanielHabenicht 2022-04-08 10:22:19 +00:00 committed by SamTV12345
parent 22704f7dff
commit bd4a4ae8cf
5 changed files with 89 additions and 2 deletions

View file

@ -634,5 +634,10 @@
"customLocaleStrings": {},
/* Disable Admin UI tests */
"enableAdminUITests": false
"enableAdminUITests": false,
/*
* Enable/Disable case-insensitive pad names.
*/
"enforceLowerCasePadIds": "${ENFORCE_LOWER_CASE_PAD_IDS:false}"
}

View file

@ -635,5 +635,10 @@
"customLocaleStrings": {},
/* Disable Admin UI tests */
"enableAdminUITests": false
"enableAdminUITests": false,
/*
* Enable/Disable case-insensitive pad names.
*/
"enforceLowerCasePadIds": false
}

View file

@ -22,6 +22,7 @@
const CustomError = require('../utils/customError');
const Pad = require('../db/Pad');
const db = require('./DB');
const settings = require('../utils/Settings');
/**
* A cache of all loaded Pads.
@ -170,6 +171,8 @@ exports.sanitizePadId = async (padId) => {
padId = padId.replace(from, to);
}
if (settings.enforceLowerCasePadIds) padId = padId.toLowerCase();
// we're out of possible transformations, so just return it
return padId;
};

View file

@ -430,6 +430,11 @@ exports.importMaxFileSize = 50 * 1024 * 1024;
*/
exports.enableAdminUITests = false;
/*
* Enable auto conversion of pad Ids to lowercase.
* e.g. /p/EtHeRpAd to /p/ehtherpad
*/
exports.enforceLowerCasePadIds = false;
// checks if abiword is avaiable
exports.abiwordAvailable = () => {

View file

@ -0,0 +1,69 @@
'use strict';
const assert = require('assert').strict;
const common = require('../common');
const padManager = require('../../../node/db/PadManager');
const settings = require('../../../node/utils/Settings');
describe(__filename, function () {
this.timeout(30000);
let agent;
const cleanUpPads = async () => {
const padIds = ['UPPERCASEpad', 'uppercasepad', 'ALREADYexistingPad', 'alreadyexistingpad'];
await Promise.all(padIds.map(async (padId) => {
if (await padManager.doesPadExist(padId)) {
const pad = await padManager.getPad(padId);
await pad.remove();
}
}));
};
before(async function () { agent = await common.init(); });
beforeEach(async function () {
await cleanUpPads();
});
afterEach(async function () {
await cleanUpPads();
});
describe('not activated', function () {
Object.assign(settings, {
enforceLowerCasePadIds: false,
});
it('- do nothing', async function () {
const res = await agent.get('/p/UPPERCASEpad');
assert.equal(res.status, 200);
});
it('- do nothingg', async function () {
await agent.get('/p/UPPERCASEpad')
.expect(200);
});
});
describe('activated', function () {
it('- lowercase pad ids', async function () {
Object.assign(settings, {
enforceLowerCasePadIds: true,
});
await agent.get('/p/UPPERCASEpad')
.expect(302)
.expect('location', 'uppercasepad');
});
it('- keeps old pads accessible', async function () {
Object.assign(settings, {
enforceLowerCasePadIds: false,
});
const pad = await padManager.getPad('ALREADYexistingPad', 'alreadyexistingpad');
await padManager.getPad('ALREADYexistingPad', 'bla');
assert.equal(pad.text(), 'alreadyexistingpad\n');
Object.assign(settings, {
enforceLowerCasePadIds: true,
});
const newpad = await padManager.getPad('alreadyexistingpad', 'testcontent');
assert.equal(newpad.text(), 'testcontent\n');
});
});
});