mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 07:56:16 -04:00
tests: URL decode test spec pathnames
Express automatically URL decodes route parameters.
This commit is contained in:
parent
998e77ec25
commit
e1c2c963f0
1 changed files with 8 additions and 9 deletions
|
@ -30,15 +30,11 @@ exports.expressCreateServer = (hookName, args, cb) => {
|
||||||
|
|
||||||
const rootTestFolder = path.join(settings.root, 'src/tests/frontend/');
|
const rootTestFolder = path.join(settings.root, 'src/tests/frontend/');
|
||||||
|
|
||||||
const url2FilePath = (url) => {
|
const sanitizePath = (subPath) => {
|
||||||
let subPath = url.substr('/tests/frontend'.length);
|
|
||||||
if (subPath === '') {
|
if (subPath === '') {
|
||||||
subPath = 'index.html';
|
subPath = 'index.html';
|
||||||
}
|
}
|
||||||
subPath = subPath.split('?')[0];
|
|
||||||
|
|
||||||
let filePath = path.join(rootTestFolder, subPath);
|
let filePath = path.join(rootTestFolder, subPath);
|
||||||
|
|
||||||
// make sure we jail the paths to the test folder, otherwise serve index
|
// make sure we jail the paths to the test folder, otherwise serve index
|
||||||
if (filePath.indexOf(rootTestFolder) !== 0) {
|
if (filePath.indexOf(rootTestFolder) !== 0) {
|
||||||
filePath = path.join(rootTestFolder, 'index.html');
|
filePath = path.join(rootTestFolder, 'index.html');
|
||||||
|
@ -46,9 +42,12 @@ exports.expressCreateServer = (hookName, args, cb) => {
|
||||||
return filePath;
|
return filePath;
|
||||||
};
|
};
|
||||||
|
|
||||||
args.app.get('/tests/frontend/specs/*', (req, res, next) => {
|
// The regexp /[\d\D]{0,}/ is equivalent to the regexp /.*/. The Express route path used here
|
||||||
|
// uses the more verbose /[\d\D]{0,}/ pattern instead of /.*/ because path-to-regexp v0.1.7 (the
|
||||||
|
// version used with Express v4.x) interprets '.' and '*' differently than regexp.
|
||||||
|
args.app.get('/tests/frontend/specs/:file([\\d\\D]{0,})', (req, res, next) => {
|
||||||
(async () => {
|
(async () => {
|
||||||
const specFilePath = url2FilePath(req.url);
|
const specFilePath = sanitizePath(`specs/${req.params.file}`);
|
||||||
const specFileName = path.basename(specFilePath);
|
const specFileName = path.basename(specFilePath);
|
||||||
let content = await fsp.readFile(specFilePath);
|
let content = await fsp.readFile(specFilePath);
|
||||||
content = `describe(${JSON.stringify(specFileName)}, function(){${content}});`;
|
content = `describe(${JSON.stringify(specFileName)}, function(){${content}});`;
|
||||||
|
@ -59,8 +58,8 @@ exports.expressCreateServer = (hookName, args, cb) => {
|
||||||
})().catch((err) => next(err || new Error(err)));
|
})().catch((err) => next(err || new Error(err)));
|
||||||
});
|
});
|
||||||
|
|
||||||
args.app.get('/tests/frontend/*', (req, res) => {
|
args.app.get('/tests/frontend/:file([\\d\\D]{0,})', (req, res) => {
|
||||||
const filePath = url2FilePath(req.url);
|
const filePath = sanitizePath(req.params.file);
|
||||||
res.sendFile(filePath);
|
res.sendFile(filePath);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue