mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-05 14:33:07 +00:00
Merge branch 'master' into preservePREColons
This commit is contained in:
@@ -14,6 +14,7 @@ const GoogleActions = require('./googleActions.js');
|
|||||||
const serveCompressedStaticAssets = require('./static-assets.mv.js');
|
const serveCompressedStaticAssets = require('./static-assets.mv.js');
|
||||||
const sanitizeFilename = require('sanitize-filename');
|
const sanitizeFilename = require('sanitize-filename');
|
||||||
const asyncHandler = require('express-async-handler');
|
const asyncHandler = require('express-async-handler');
|
||||||
|
const templateFn = require('./../client/template.js');
|
||||||
|
|
||||||
const { DEFAULT_BREW } = require('./brewDefaults.js');
|
const { DEFAULT_BREW } = require('./brewDefaults.js');
|
||||||
|
|
||||||
@@ -420,8 +421,16 @@ if(isLocalEnvironment){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Send rendered page
|
||||||
|
app.use(asyncHandler(async (req, res, next)=>{
|
||||||
|
if (!req.route) return res.redirect('/'); // Catch-all for invalid routes
|
||||||
|
|
||||||
|
const page = await renderPage(req, res);
|
||||||
|
if(!page) return;
|
||||||
|
res.send(page);
|
||||||
|
}));
|
||||||
|
|
||||||
//Render the page
|
//Render the page
|
||||||
const templateFn = require('./../client/template.js');
|
|
||||||
const renderPage = async (req, res)=>{
|
const renderPage = async (req, res)=>{
|
||||||
// Create configuration object
|
// Create configuration object
|
||||||
const configuration = {
|
const configuration = {
|
||||||
@@ -450,13 +459,6 @@ const renderPage = async (req, res)=>{
|
|||||||
return page;
|
return page;
|
||||||
};
|
};
|
||||||
|
|
||||||
//Send rendered page
|
|
||||||
app.use(asyncHandler(async (req, res, next)=>{
|
|
||||||
const page = await renderPage(req, res);
|
|
||||||
if(!page) return;
|
|
||||||
res.send(page);
|
|
||||||
}));
|
|
||||||
|
|
||||||
//v=====----- Error-Handling Middleware -----=====v//
|
//v=====----- Error-Handling Middleware -----=====v//
|
||||||
//Format Errors as plain objects so all fields will appear in the string sent
|
//Format Errors as plain objects so all fields will appear in the string sent
|
||||||
const formatErrors = (key, value)=>{
|
const formatErrors = (key, value)=>{
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ renderer.link = function (href, title, text) {
|
|||||||
if(href[0] == '#') {
|
if(href[0] == '#') {
|
||||||
self = true;
|
self = true;
|
||||||
}
|
}
|
||||||
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
|
href = cleanUrl(href);
|
||||||
|
|
||||||
if(href === null) {
|
if(href === null) {
|
||||||
return text;
|
return text;
|
||||||
@@ -734,28 +734,14 @@ Marked.use(mustacheInjectBlock);
|
|||||||
Marked.use({ renderer: renderer, tokenizer: tokenizer, mangle: false });
|
Marked.use({ renderer: renderer, tokenizer: tokenizer, mangle: false });
|
||||||
Marked.use(MarkedExtendedTables(), MarkedGFMHeadingId(), MarkedSmartypantsLite(), MarkedEmojis(MarkedEmojiOptions));
|
Marked.use(MarkedExtendedTables(), MarkedGFMHeadingId(), MarkedSmartypantsLite(), MarkedEmojis(MarkedEmojiOptions));
|
||||||
|
|
||||||
const nonWordAndColonTest = /[^\w:]/g;
|
function cleanUrl(href) {
|
||||||
const cleanUrl = function (sanitize, base, href) {
|
try {
|
||||||
if(sanitize) {
|
href = encodeURI(href).replace(/%25/g, '%');
|
||||||
let prot;
|
} catch {
|
||||||
try {
|
return null;
|
||||||
prot = decodeURIComponent(unescape(href))
|
}
|
||||||
.replace(nonWordAndColonTest, '')
|
return href;
|
||||||
.toLowerCase();
|
}
|
||||||
} catch (e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if(prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
href = encodeURI(href).replace(/%25/g, '%');
|
|
||||||
} catch (e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return href;
|
|
||||||
};
|
|
||||||
|
|
||||||
const escapeTest = /[&<>"']/;
|
const escapeTest = /[&<>"']/;
|
||||||
const escapeReplace = /[&<>"']/g;
|
const escapeReplace = /[&<>"']/g;
|
||||||
|
|||||||
Reference in New Issue
Block a user