Skip to content
Snippets Groups Projects
Commit a3e3111c authored by David Mynors's avatar David Mynors
Browse files

Linkify oc-user and mastodon from form-submissions

This makes it easier for community WG members to click
parent 965309be
Branches
No related tags found
No related merge requests found
{
"trailingComma": "es5",
"tabWidth": 4,
"semi": true,
"singleQuote": true
}
module.exports = function (rawUrl, prefix) {
const url = rawUrl.trim()
if (!url.startsWith('http')) {
if (url.startsWith(prefix)) {
return 'https://' + url;
} else {
if (url.startsWith('/') && prefix.endsWith('/')) {
return 'https://' + prefix + url.split('/')[1];
}
if (!url.startsWith('/') && !prefix.endsWith('/')) {
return 'https://' + prefix + '/' + url;
}
return 'https://' + prefix + url;
}
}
return url;
};
const test = require('ava');
const linkify = require('../linkify.js');
test("doesn't mangle good urls", (t) => {
const httpsUrl = 'https://opencollective.com/example';
const httpUrl = ' http://opencollective.com/example';
t.is(linkify(httpsUrl, 'opencollective.com'), httpsUrl);
t.is(linkify(httpUrl, 'opencollective.com'), httpUrl.trim());
});
test('linkifies urls without http', (t) => {
const url = 'social.coop/foobar ';
t.is(linkify(url, 'social.coop'), 'https://social.coop/foobar');
});
test('linkifies urls without prefix', (t) => {
const url = 'foobar';
t.is(linkify(url, 'social.coop'), 'https://social.coop/foobar');
});
test('does the right thing about slash before the prefix', (t) => {
const withSlash = ' /foobar ';
const withoutSlash = 'foobar';
desiredUrl = 'https://social.coop/foobar';
t.is(linkify(withSlash, 'social.coop'), desiredUrl);
t.is(linkify(withoutSlash, 'social.coop'), desiredUrl);
t.is(linkify(withSlash, 'social.coop/'), desiredUrl);
t.is(linkify(withoutSlash, 'social.coop/'), desiredUrl);
});
This diff is collapsed.
......@@ -7,7 +7,7 @@
"prebuild": "test -d src || git clone git@git.coop:social.coop/general.wiki.git src",
"build": "node build.js",
"serve": "node serve.js",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "ava"
},
"author": "wu-lee <wu_lee@social.coop>",
"license": "AGPL-3.0-only",
......@@ -33,5 +33,7 @@
"shelljs": "^0.8.3",
"winston": "^3.2.1"
},
"devDependencies": {}
"devDependencies": {
"ava": "^3.15.0"
}
}
......@@ -11,6 +11,7 @@ const git = require('./lib/git.js')({});
const loggers = require('./lib/logging.js').loggers;
const config = require('./lib/config.js');
const spamTrap = require('./lib/spam-trap.js')(config.spamTraps);
const linkify = require('./lib/linkify.js');
const buildlog = loggers.build;
const httplog = loggers.http;
......@@ -140,6 +141,8 @@ app.post('/registration', (req, res) => {
return (err) => submitlog.info(`$message: `, err);
}
req.body['oc-user'] = linkify(req.body['oc-user'], 'opencollective.com')
// This function logs spamtrap hits, we just need to drop spam.
// Previously we sent a false ack email to spam requests, but
// this was causing problems with Mailgun! So, no more false acks.
......@@ -210,6 +213,9 @@ app.post('/meet.coop-registration-form', (req, res) => {
return (err) => submitlog.info(`$message: `, err);
}
req.body['oc-user'] = linkify(req.body['oc-user'], 'opencollective.com')
req.body['mastodon'] = linkify(req.body['mastodon'], 'social.coop')
if (!spamTrap(req.body)) {
console.log("ok")
if (req.body.email) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment