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

camelcase requirement causes uncaught exception error with version 1.1.0 of http-proxy-middleware #513

Closed
lpbz opened this issue Apr 2, 2021 · 14 comments · Fixed by #516

Comments

@lpbz
Copy link

lpbz commented Apr 2, 2021

Following the upgrade to v1.1.0 of http-proxy-middleware, my application started spamming uncaught exception errors during to an invalid regular expression: /[_.\- ]+([\p{Alpha}\p{N}_]|$)/:

Full error message:

2021-04-01 17:50:58.156 C | UNCAUGHT EXCEPTION: Invalid regular expression: /[_.\- ]+([\p{Alpha}\p{N}_]|$)/: Invalid escape
2021-04-01 17:50:58.157 C | SyntaxError: Invalid regular expression: /[_.\- ]+([\p{Alpha}\p{N}_]|$)/: Invalid escape

The invalid regular expression that this is complaining about results from the import of camelcase (v.6.2.0). The index.js of camelcase contains this function:

const postProcess = (input, options) => {
        return input.replace(/[_.\- ]+([\p{Alpha}\p{N}_]|$)/gu, (_, p1) => p1.toLocaleUpperCase(options.locale))
                .replace(/\d+([\p{Alpha}\p{N}_]|$)/gu, m => m.toLocaleUpperCase(options.locale));
};

client info

RHEL 6/7

@chimurai
Copy link
Owner

chimurai commented Apr 2, 2021

Thanks for reporting.
Can you provide a minimal reproducible example or the value which causes this issue?

//cc @TrySound

@lpbz
Copy link
Author

lpbz commented Apr 2, 2021

I'm not a developer of the application so I'm not intimately acquainted with what we are calling that could be causing this in the backend.

It seems to result from the introduction of this commit https://github.com/chimurai/http-proxy-middleware/pull/507/files which causes the application to pull down the camelcase node module library.

I have a snapshot of the application in the working state and in the broken state and the only difference is the upgrade to 1.1.0 of http-proxy-middleware and the introduction of the camelcase 6.2.0 dependency.

@lpbz
Copy link
Author

lpbz commented Apr 2, 2021

I'm wondering if this piece of code causes the issue:

target: 'ws://localhost:7529',

@chimurai
Copy link
Owner

chimurai commented Apr 2, 2021

Can you give a try with http-proxy-middleware@1.1.1-alpha.1 ?
I removed the camelcase dependency here.

camelcase is only used if you subscribe to events from http-proxy.

If that doesn't help it would be helpful if you can share you proxy configuration:

createProxyMiddleware({
  target: 'ws://localhost:7529',
  ...
})

@chimurai
Copy link
Owner

chimurai commented Apr 2, 2021

These were basically the conversions done internally:

https://npm.runkit.com/camelcase

const camelCase = require("camelcase")

console.log(camelCase('on error'));      // "onError"
console.log(camelCase('on proxyReq'));   // "onProxyReq"
console.log(camelCase('on proxyReqWs'))  // "onProxyReqWs"
console.log(camelCase('on proxyRes'));   // "onProxyRes"
console.log(camelCase('on open'));       // "onOpen"
console.log(camelCase('on close'));      // "onClose"

@chimurai
Copy link
Owner

chimurai commented Apr 2, 2021

I'm wondering if this piece of code causes the issue:
target: 'ws://localhost:7529',

Seems to work.
Tested this with example in https://github.com/chimurai/http-proxy-middleware/blob/master/examples/websocket/index.js:

const wsProxy = createProxyMiddleware('/', {
  target: 'ws://echo.websocket.org',
  changeOrigin: true, // for vhosted sites, changes host header to match to target's host
});

@jens-maus
Copy link

jens-maus commented Apr 8, 2021

@chimurai Hi, I just got hit by the exact same issue here in one of my applications (cf. jens-maus/RaspberryMatic#1087 (comment)) and I wonder if you have any plans to quickly release a minor official fix update to npm during the next days because my current build environment always grabs the latest version of http-proxy-middleware but obviously version 1.1.0 is broken due to this camelcase issue? Would be really great if you could consider sending out a minor 1.1.1 fix update because I want to release an update of my app during the next days.

@TrySound
Copy link
Contributor

TrySound commented Apr 8, 2021

@jens-maus Which node version do you use?

@jens-maus
Copy link

@jens-maus Which node version do you use?

12.22.1

@chimurai
Copy link
Owner

chimurai commented Apr 9, 2021

Fix was already published in alpha version: http-proxy-middleware@1.1.1-alpha.1 #513 (comment)

Was waiting for a confirmation of the hotfix before publishing the final version, since no reproducible example was provided.

@jens-maus Would be great if you could give a try with http-proxy-middleware@1.1.1-alpha.1 to confirm the fix.

@chimurai
Copy link
Owner

published http-proxy-middleware@1.1.1

@jens-maus
Copy link

@jens-maus Would be great if you could give a try with http-proxy-middleware@1.1.1-alpha.1 to confirm the fix.

I just could test the latest 1.1.1 version and the issue is definitely fixed in that version. Thanks!

@chimurai
Copy link
Owner

Thanks for verifying the fix @jens-maus! (Sorry for the inconvenience.)

Although not an issue anymore in http-proxy-middleware; Think you might have bumped into a bug in the camelcase library. (Without a reproducible example it'll difficult to pin-point).

@lpbz
Copy link
Author

lpbz commented Apr 11, 2021

@chimurai 1.1.1-alpha.1 was not working for me and actually caused my application to crash. I must've not called it correctly in the package.json. But http-proxy-middleware@1.1.1 worked for my application...everything looks great.

Thanks for taking care of this.

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

Successfully merging a pull request may close this issue.

4 participants