A
A
Abc Edc2015-04-13 12:17:34
Node.js
Abc Edc, 2015-04-13 12:17:34

How to fix non-standard characters in node js?

My get requests to search for something do not go away if, for example, I write like this: server/required_item?param1=abcd#2 343¶m2=%873467
At the same time, I understand that it is unlikely that I will have such records in the database at all. BUT still I want to foresee everything, while such parameters in put / post work as they should

.update({_id: req.params.id}, req.body , function(err,object){
            if (err)  res.json({"update":err});
            res.json({"update":"yeaah!!"});
        })

and here
.find(req.query,function(err,object){
            if(object){
                res.json(object);
            }
            else {
                res.json({"object":"notFound"});
            }
        });

Here the answer is just {}
empty
But
сервер/необходимый_итем?парам1=КрасивоИмя Без Инородных символов&парам2=и ТУут

Works
How all the same to be? if the user fills in with characters (don't say pregmatches/validations can be done)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kitmanov, 2015-04-13
@gleber1

Well, for starters, everything after the lattice is considered an anchor and does not stupidly go to the server. So if you have directly such requests as you have given, then that's why it does not work.
In general, you just need to do encodeURIComponent on the client, and the server itself will do the decodeURIComponent. If the user manually types crap in the address bar, then he is SSZB.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question