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

RegExp variable seems changed its type after passing to another function #8206

Open
2 tasks done
xueqino1 opened this issue Aug 18, 2024 · 2 comments
Open
2 tasks done
Labels

Comments

@xueqino1
Copy link

xueqino1 commented Aug 18, 2024

  • Bug Report

as the following codes show, I pass the variable /^/test1(.*)?$/ to function unless,when I run those code in nodejs(v16.9.1) , it works fine .when I access /login and /test1 , the console doesn't log 'customMiddleware called'. which means variable vv matchs the string '/test1' while '/login' matchs the string '/login'.

then I put those code in a html and run it in nwjs , when I access /login, it works fun, the console doesn't log anything. but when I access /test1, the console output 'customMiddleware called', which means vv didn't match the string '/test1'. I add some console code in function unless, it showed that (vv instanceof RexExp) is false and typeof vv is 'object'.

I run it in nwjs v0.70.1 and v0.90.0 , both not work.

  • Successfully reproduced against the latest version of NW.js?
    YES

  • Operating System:windows 10

  • NW.js Version:nwjs-sdk-v0.70.1-win-x64 and nwjs-sdk-v0.90.0-win-x64

  • Code snippet:
    `
    const express=require('express')
    const express_unless_1 = require("express-unless");
    const app=express()

const customMiddleware = function (req, res, next) {
console.log('customMiddleware called');
next();
};
customMiddleware.unless=express_unless_1.unless;

const vv = /^/test1(.*)?$/
console.log('vv is regexp:',vv instanceof RegExp)
app.use(customMiddleware.unless({
path: ["/login",vv]
}))

app.get('/test',(req,res)=>{
res.send('test ')
})

app.get('/login',(req,res)=>{
res.send('login ')
})
app.listen(3000,()=>{
console.log('app listen 3000')
})
`

@ayushmanchhabra
Copy link
Contributor

Trying to understand the issue.. on first glance this looks more of a code issue than a NW.js API issue. From what I understand, vv should be a RegExp but it changes to Object type?

@xueqino1
Copy link
Author

yes ,you're right. vv is a RegExp, then it is passed to function unless as options {path: [vv]}. the function unless looks like
function unless(opts) {
const paths = toArray(opts.path);
paths.some(function (p) {
console.log(p,"---------------",typeof p,"---------------", p instanceof RegExp)
}
}

when running in node, "p instanceof RegExp" outputs true . but when running in nwjs, it outputs false.

I run into this issue when I browse the '/test1', it's expected to match the vv and ignore the middleware, but it works fine in node and doesn't work in nwjs.

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