Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apos2.222.0 - Invalid RegEx path.sep missing "\" #3876

Open
nicholasbester opened this issue Sep 5, 2022 · 1 comment
Open

Apos2.222.0 - Invalid RegEx path.sep missing "\" #3876

nicholasbester opened this issue Sep 5, 2022 · 1 comment
Assignees
Labels

Comments

@nicholasbester
Copy link

Even though it isn't recommended to run ApostropheCMS on Windows, I've found a small bug which is worth opening a PR for.

To Reproduce

Step by step instructions to reproduce the behavior:

  1. Running ApostropheCMS 2 branch release-2.222.0 on Windows
  2. npm i installs packages fine on Node 14,16 and 18
  3. npm start is throwing an error with an invalid regular expression

Expected behavior

Apostrophe should start as expected

Describe the bug

Getting the following error when starting Apostrophe on a Windows environment:

kiichiro-toyoda-cms\node_modules\apostrophe\index.js:58
throw err;
^

SyntaxError: Invalid regular expression: /\node_modules\mocha\/: \ at end of pattern
at new RegExp (<anonymous>)
at getRoot (C:\Users\user\WebStormProjects\kiichiro-toyoda-cms\node_modules\apostrophe\index.js:259:35)
at module.exports (C:\Users\user\WebStormProjects\kiichiro-toyoda-cms\node_modules\apostrophe\index.js:35:33)
at Object.<anonymous> (C:\Users\user\WebStormProjects\kiichiro-toyoda-cms\app.js:334:35)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at internal/main/run_main_module.js:17:47
[nodemon] app crashed - waiting for file changes before starting...

A small update is required to a specific line within the root index.js file of the apostrophe release-2.222.0 branch, the following on line 259 should be updated from:

if (m.parent.filename.match(new RegExp(`${path.sep}node_modules${path.sep}mocha${path.sep}`))) {

to:

if (m.parent.filename.match(new RegExp(`${path.sep}node_modules${path.sep}mocha\${path.sep}`))) {

Details

Windows uses

Version of Node.js:
Tested on Node 14, 16 and 18

Server Operating System:
Microsoft Windows

Additional context:
This is specific to Microsoft Windows, after forking at testing the above fix Apostrophe starts as expected including on both Linux and Mac.

@nicholasbester nicholasbester changed the title Invalid RegEx path.sep missing "\" Apos2.222.0 - Invalid RegEx path.sep missing "\" Sep 5, 2022
@boutell
Copy link
Member

boutell commented Sep 7, 2022

Makes sense to submit a PR, please do. But the right way to avoid this would be to use self.apos.utils.regExpQuote so that you don't wind up with an unnecessary escape character for non-Windows path characters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants