0

Please I am working on a project that takes the req.query part of a url and checks if its a correct fraction or not i.e.

1/2 // This is a valid fraction 1//2 // This is an Invalid fraction

The problem is when it receives a URL like this https://rough-volcano-starburst.glitch.me/api/convert?input=1//2gal

app.route('/api/convert')
    .get(function (req, res){
      let input =  req.query.input;

}

The input variable shows '1/2gal'

It doesn't matter how many slashes I put, I still get 1/2gal.

Please help.

Rocklanna
  • 1
  • 1
  • Hello Welcome to SE! Use post or escape https://stackoverflow.com/questions/2992231/slashes-in-url-variables – CharybdeBE Feb 23 '21 at 15:41
  • 1
    Does this answer your question? [slashes in url variables](https://stackoverflow.com/questions/2992231/slashes-in-url-variables) – CharybdeBE Feb 23 '21 at 15:41
  • Hi @CharybdeBE thanks for the response. I already tried encoding it but it only returns 1%2F2gal instead of 1%2F%2F2gal – Rocklanna Feb 24 '21 at 06:51
  • You encode when you send and then you decode when you receive, and then you can evaluate if its a correct fraction – CharybdeBE Feb 24 '21 at 08:24
  • Hi @CharybdeBE, let me explain further. I wrote a freecodecamp project. When i submit my solution link, it runs my code against FCC test cases which means there is no way for me to encode their URL variable before it reaches my function ```app.route('/api/convert').get(function (req, res){ let input = req.query.input; } ``` – Rocklanna Feb 24 '21 at 08:32

0 Answers0