Skip to content

Commit

Permalink
(fix) Address some minor issues with regexes in development code
Browse files Browse the repository at this point in the history
  • Loading branch information
ibacher committed Nov 21, 2023
1 parent 52fcfc3 commit 9e35d61
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion packages/shell/esm-app-shell/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ function checkDirectoryHasContents(dirName) {
}
}

// taken from: https://stackoverflow.com/a/6969486
// this function is CC BY-SA 4.0
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}

/**
* @param {*} env
* @param {*} argv
Expand Down Expand Up @@ -160,7 +166,9 @@ module.exports = (env, argv = {}) => {
historyApiFallback: {
rewrites: [
{
from: new RegExp(`^${openmrsPublicPath}/.*(?!\.(?!html).+$)`),
from: new RegExp(
`^${escapeRegExp(openmrsPublicPath)}/.*(?!\\.(?!html).+$)`
),
to: `${openmrsPublicPath}/index.html`,
},
],
Expand Down
4 changes: 2 additions & 2 deletions packages/tooling/openmrs/src/commands/develop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ export function runDevelop(args: DevelopArgs) {
.replace(/href="\/openmrs\/spa/g, `href="${spaPath}`)
.replace(/src="\/openmrs\/spa/g, `src="${spaPath}`)
.replace(
/https:\/\/dev3.openmrs.org\/openmrs\/spa\/importmap\.json/g,
/https:\/\/dev3\.openmrs\.org\/openmrs\/spa\/importmap\.json/g,
`http://${host}:${port}${spaPath}/importmap.json`
);

const sw = resolve(source, "service-worker.js");
// remove any full references to dev3.openmrs.org
const swContent = readFileSync(sw, "utf-8").replace(
/https:\/\/dev3.openmrs.org\/openmrs\/spa\//g,
/https:\/\/dev3\.openmrs\.org\/openmrs\/spa\//g,
``
);

Expand Down

0 comments on commit 9e35d61

Please sign in to comment.