Metric-Imperial Converter -- Consecutive slashes in test case URL resolves to one

My projects is working fine with all functional and unit test passing but when I pass the solution link to FCC the below tests fail.

If the number is invalid, returned will be `invalid number’
If both the unit and number are invalid, returned will be ‘invalid number and unit’

Reason:

The below tests being passed by FCC fail.

async getUserInput => {
  try {
    const data = await $.get(
      getUserInput('url') + '/api/convert?input=1//2gal'
    );
    assert(data.error === 'invalid number' || data === 'invalid number');
  } catch (xhr) {
    throw new Error(xhr.responseText || xhr.message);
  }
};


async getUserInput => {
  try {
    const data = await $.get(
      getUserInput('url') + '/api/convert?input=1//2min'
    );
    assert(
      data.error === 'invalid number and unit' ||
        data === 'invalid number and unit'
    );
  } catch (xhr) {
    throw new Error(xhr.responseText || xhr.message);
  }
};

I found out that what my input variable receives with the below code is 1/2gal and 1/2min respectively.
No matter the number of consecutive slashes I add in the URL, it still resolves to 1/2gal

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

However if I pass this example through my app and click convert, it returns the correct result, “invalid number”

Please help.
Your project link(s)

solution: https://rough-volcano-starburst.glitch.me

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36.

Challenge: Metric-Imperial Converter

Link to the challenge:

@Sky020 Please could you assist in looking at my issue. Many thanks

Welcome, Rocklanna.

The only way I have been able to test this is with links like:

https://efficacious-superficial-dress.glitch.me/api/convert?input=%271//2gal%27

Where %27 is a quotation mark (')

Event that is not working as expected. So, I suspect this is specific to how Glitch internally handles forward slashes in strings. I might do some more digging, later.

Hope you are able to move forward

Thank a lot for the response. I will also use Repl.it and see if it works on there.

This is a link to my project code.

I imported your code from Glitch to Repl, and it works as expected. Glitch must do some behind-the-scenes parsing on the URLs.

Hope this has helped

1 Like

Thanks, finally submitted. Finished that project in 1 day and been looking for a fix for 5days now. Thanks a lot