mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-06 03:32:40 +00:00
Merge branch 'master' into issue_4105
This commit is contained in:
@@ -69,14 +69,11 @@ const corsOptions = {
|
|||||||
'https://homebrewery-stage.herokuapp.com',
|
'https://homebrewery-stage.herokuapp.com',
|
||||||
];
|
];
|
||||||
|
|
||||||
if(isLocalEnvironment) {
|
const localNetworkRegex = /^http:\/\/(localhost|127\.0\.0\.1|10\.\d+\.\d+\.\d+|192\.168\.\d+\.\d+|172\.(1[6-9]|2\d|3[0-1])\.\d+\.\d+):\d+$/;
|
||||||
const localNetworkRegex = /^http:\/\/(localhost|127\.0\.0\.1|10\.\d+\.\d+\.\d+|192\.168\.\d+\.\d+|172\.(1[6-9]|2\d|3[0-1])\.\d+\.\d+):\d+$/;
|
|
||||||
allowedOrigins.push(localNetworkRegex);
|
|
||||||
}
|
|
||||||
|
|
||||||
const herokuRegex = /^https:\/\/(?:homebrewery-pr-\d+\.herokuapp\.com|naturalcrit-pr-\d+\.herokuapp\.com)$/; // Matches any Heroku app
|
const herokuRegex = /^https:\/\/(?:homebrewery-pr-\d+\.herokuapp\.com|naturalcrit-pr-\d+\.herokuapp\.com)$/; // Matches any Heroku app
|
||||||
|
|
||||||
if(!origin || allowedOrigins.includes(origin) || herokuRegex.test(origin)) {
|
if(!origin || allowedOrigins.includes(origin) || herokuRegex.test(origin) || (isLocalEnvironment && localNetworkRegex.test(origin))) {
|
||||||
callback(null, true);
|
callback(null, true);
|
||||||
} else {
|
} else {
|
||||||
console.log(origin, 'not allowed');
|
console.log(origin, 'not allowed');
|
||||||
|
|||||||
@@ -60,6 +60,11 @@ mathParser.functions.signed = function (a) {
|
|||||||
return `${a}`;
|
return `${a}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Normalize variable names; trim edge spaces and shorten blocks of whitespace to 1 space
|
||||||
|
const normalizeVarNames = (label)=>{
|
||||||
|
return label.trim().replace(/\s+/g, ' ');
|
||||||
|
};
|
||||||
|
|
||||||
//Processes the markdown within an HTML block if it's just a class-wrapper
|
//Processes the markdown within an HTML block if it's just a class-wrapper
|
||||||
renderer.html = function (token) {
|
renderer.html = function (token) {
|
||||||
let html = token.text;
|
let html = token.text;
|
||||||
@@ -509,7 +514,7 @@ const replaceVar = function(input, hoist=false, allowUnresolved=false) {
|
|||||||
const match = regex.exec(input);
|
const match = regex.exec(input);
|
||||||
|
|
||||||
const prefix = match[1];
|
const prefix = match[1];
|
||||||
const label = match[2];
|
const label = normalizeVarNames(match[2]); // Ensure the label name is normalized as it should be in the var stack.
|
||||||
|
|
||||||
//v=====--------------------< HANDLE MATH >-------------------=====v//
|
//v=====--------------------< HANDLE MATH >-------------------=====v//
|
||||||
const mathRegex = /[a-z]+\(|[+\-*/^(),]/g;
|
const mathRegex = /[a-z]+\(|[+\-*/^(),]/g;
|
||||||
@@ -664,8 +669,8 @@ function MarkedVariables() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if(match[3]) { // Block Definition
|
if(match[3]) { // Block Definition
|
||||||
const label = match[4] ? match[4].trim().replace(/\s+/g, ' ') : null; // Trim edge spaces and shorten blocks of whitespace to 1 space
|
const label = match[4] ? normalizeVarNames(match[4]) : null;
|
||||||
const content = match[5] ? match[5].trim().replace(/[ \t]+/g, ' ') : null; // Trim edge spaces and shorten blocks of whitespace to 1 space
|
const content = match[5] ? match[5].trim().replace(/[ \t]+/g, ' ') : null; // Normalize text content (except newlines for block-level content)
|
||||||
|
|
||||||
varsQueue.push(
|
varsQueue.push(
|
||||||
{ type : 'varDefBlock',
|
{ type : 'varDefBlock',
|
||||||
@@ -674,7 +679,7 @@ function MarkedVariables() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if(match[6]) { // Block Call
|
if(match[6]) { // Block Call
|
||||||
const label = match[7] ? match[7].trim().replace(/\s+/g, ' ') : null; // Trim edge spaces and shorten blocks of whitespace to 1 space
|
const label = match[7] ? normalizeVarNames(match[7]) : null;
|
||||||
|
|
||||||
varsQueue.push(
|
varsQueue.push(
|
||||||
{ type : 'varCallBlock',
|
{ type : 'varCallBlock',
|
||||||
@@ -683,7 +688,7 @@ function MarkedVariables() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if(match[8]) { // Inline Definition
|
if(match[8]) { // Inline Definition
|
||||||
const label = match[10] ? match[10].trim().replace(/\s+/g, ' ') : null; // Trim edge spaces and shorten blocks of whitespace to 1 space
|
const label = match[10] ? normalizeVarNames(match[10]) : null;
|
||||||
let content = match[11] || null;
|
let content = match[11] || null;
|
||||||
|
|
||||||
// In case of nested (), find the correct matching end )
|
// In case of nested (), find the correct matching end )
|
||||||
@@ -715,7 +720,7 @@ function MarkedVariables() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if(match[12]) { // Inline Call
|
if(match[12]) { // Inline Call
|
||||||
const label = match[13] ? match[13].trim().replace(/\s+/g, ' ') : null; // Trim edge spaces and shorten blocks of whitespace to 1 space
|
const label = match[13] ? normalizeVarNames(match[13]) : null;
|
||||||
|
|
||||||
varsQueue.push(
|
varsQueue.push(
|
||||||
{ type : 'varCallInline',
|
{ type : 'varCallInline',
|
||||||
|
|||||||
@@ -410,4 +410,29 @@ describe('Regression Tests', ()=>{
|
|||||||
const rendered = Markdown.render(source).trimReturns();
|
const rendered = Markdown.render(source).trimReturns();
|
||||||
expect(rendered).toBe('<table><thead><tr><th>title 1</th><th>title 2</th><th>title 3</th><th>title 4</th></tr></thead><tbody><tr><td><a href=\"bar\">foo</a></td><td>Ipsum</td><td>)</td><td>)</td></tr></tbody></table>');
|
expect(rendered).toBe('<table><thead><tr><th>title 1</th><th>title 2</th><th>title 3</th><th>title 4</th></tr></thead><tbody><tr><td><a href=\"bar\">foo</a></td><td>Ipsum</td><td>)</td><td>)</td></tr></tbody></table>');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Handle Extra spaces in image alt-text 1', function(){
|
||||||
|
const source='';
|
||||||
|
const rendered = Markdown.render(source).trimReturns();
|
||||||
|
expect(rendered).toBe('<p><img src=\"http://i.imgur.com/hMna6G0.png\" alt=\"where is my image??\" style=\"--HB_src:url(http://i.imgur.com/hMna6G0.png);\"></p>');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Handle Extra spaces in image alt-text 2', function(){
|
||||||
|
const source='';
|
||||||
|
const rendered = Markdown.render(source).trimReturns();
|
||||||
|
expect(rendered).toBe('<p><img src=\"http://i.imgur.com/hMna6G0.png\" alt=\"where is my image??\" style=\"--HB_src:url(http://i.imgur.com/hMna6G0.png);\"></p>');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Handle Extra spaces in image alt-text 3', function(){
|
||||||
|
const source='';
|
||||||
|
const rendered = Markdown.render(source).trimReturns();
|
||||||
|
expect(rendered).toBe('<p><img src=\"http://i.imgur.com/hMna6G0.png\" alt=\"where is my image??\" style=\"--HB_src:url(http://i.imgur.com/hMna6G0.png);\"></p>');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Handle Extra spaces in image alt-text 4', function(){
|
||||||
|
const source='{height=20%,width=20%}';
|
||||||
|
const rendered = Markdown.render(source).trimReturns();
|
||||||
|
expect(rendered).toBe('<p><img style=\"--HB_src:url(http://i.imgur.com/hMna6G0.png);\" src=\"http://i.imgur.com/hMna6G0.png\" alt=\"where is my image??\" height=\"20%\" width=\"20%\"></p>');
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user