Route for Cyrillians in Express
-
I'm trying to make the router pass the phrases with letters and symbols, like
a-zA-Z0-9А-Яа-я_
♪ How am I doing this:rootApp.all(/\+(\w+|\p{L}+)/, function (req, res, next) { res.cookie("referer", req.params[0]); res.send(req.params); });
But eventually. ♪ ♪
GET /+А - 404 NOT FOUND GET /+ref - {"0":"ref"} GET /+ref_123ру_ - {"0":"ref_123"}
How do you make the passer miss the kirillian?UPDATE: It turns out that the reference is codified by URL by symbols. Even if you decode it, the password doesn't work.
rootApp.all(/\+(\S)/, function (req, res, next) { var decodedPath = decodeURIComponent(req.path), regexp = /\+(\w+|\p{IsCyrillic}+|\p{L}+)/;
console.log(decodedPath); if (regexp.test(decodedPath)) { var parsed = regexp.exec(decodedPath); console.log("Parsed String: ", parsed); res.cookie("referer", parsed[1]); res.send(parsed); } else next();
});
Consul
/+ref_123ру_
Parsed String: [ '+ref_123', 'ref_123', index: 1, input: '/+ref_123ру_' ]
-
In the end, it did so:
rootApp.all(/\+(\S+)/, function (req, res, next) { var decodedPath = decodeURIComponent(req.path), regexp = /\+[a-zA-Z0-9А-Яа-я_]+/;
var executed = regexp.exec(decodedPath); if (executed != null) { var parsed = executed[0].slice(1); res.cookie("referer", parsed); res.send(parsed); } else next();
});
Thank you, everyone!