Skip to content

Commit bebc9a0

Browse files
committed
fix: prod minify we cannot inline files which has regular expressions using /*/ syntax
1 parent acaadae commit bebc9a0

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

gulpfile.js/index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,25 @@ function extractRequireTextFragments(fileContent) {
493493
return result;
494494
}
495495

496+
function containsRegExpExcludingEmpty(str) {
497+
// This pattern attempts to match a RegExp literal, starting and ending with slashes,
498+
// containing at least one character that's not a slash or a space in between,
499+
// and possibly followed by RegExp flags. This excludes simple "//".
500+
let lines = str.split(("\n"));
501+
const regExpPatternEq = /=\s*\/(?!\/\^)(?:[^\/\s]|\\\/)+\/[gimuy]*/; // matched x=/reg/i
502+
const regExpPatternProp = /:\s*\/(?!\/\^)(?:[^\/\s]|\\\/)+\/[gimuy]*/; // matched x: /reg/i
503+
const regExpPatternCond = /\(\s*\/(?!\/\^)(?:[^\/\s]|\\\/)+\/[gimuy]*/; // matched if(/reg/i
504+
505+
for(let line of lines) {
506+
if(regExpPatternEq.test(line) || regExpPatternProp.test(line) || regExpPatternCond.test(line)) {
507+
console.error("detected regular expression in line: ", line);
508+
return line;
509+
}
510+
}
511+
return false;
512+
}
513+
514+
496515
const textContentMap = {};
497516
function inlineTextRequire(file, content, srcDir) {
498517
if(content.includes(`'text!`) || content.includes("`text!")) {
@@ -518,6 +537,13 @@ function inlineTextRequire(file, content, srcDir) {
518537
console.log("Not inlining JS/JSON file:", requirePath);
519538
} else {
520539
console.log("Inlining", requireStatement);
540+
if((requireStatement.includes(".html") || requireStatement.includes(".js"))
541+
&& containsRegExpExcludingEmpty(textContent)){
542+
console.log(textContent);
543+
const detectedRegEx = containsRegExpExcludingEmpty(textContent);
544+
throw `Error inlining ${requireStatement} in ${file}: Regex: ${detectedRegEx}`+
545+
"\nRegular expression of the form /*/ is not allowed for minification please use RegEx constructor";
546+
}
521547
content = content.replaceAll(requireStatement, "`"+textContent+"`");
522548
}
523549
}

src/extensionsIntegrated/Phoenix-live-preview/markdown.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
}, false);
7676
function getAbsoluteUrl(url) {
7777
// Check if the URL is already absolute
78-
if (/^(?:[a-z]+:)?\/\//i.test(url)) {
78+
if (new RegExp("^(?:[a-z]+:)?\\/\\/", "i").test(url)) {
7979
return url; // The URL is already absolute
8080
}
8181

0 commit comments

Comments
 (0)