Home > database >  query value should not change in express js
query value should not change in express js

Time:12-07

Problem: The value that comes as a query changes without intervention.

// url: "http://localhost:4000/sr?q=ütü"

export const search = async (req: Request, res: Response) => {
  try {
    const query = String(req.query.q)
    console.log("query: ", query);
    /*
       query value

       recived: ütü
       expected: ütü
    */
    const deeplink: string = `test://?Page=Search&Query=${query}`;
    res.status(200).send(deeplink);
  } catch (error) {
    console.error("error: ", error);
    return res.status(500).json("Internal Server Error");
  }
};

The value I want here is "ütü". But when I do console.log, the value I get is "ütü".

CodePudding user response:

I found the solution 2 minutes after it was posted by playing with the codes. Normally I can delete it but I'm not deleting it as it might help someone.

console.log("query: ", encodeURI(query));
// ütü
  • Related