The tests validator seems not detecting the invalid URL message

Tell us what’s happening:
I completed the Url shortner chalenge but the test keeps telling me that

If you pass an invalid URL that doesn’t follow the valid http://www.example.com format, the JSON response will contain { error: 'invalid url' }

While the property is already running .

Your project link(s)

githubLink: GitHub - Smaily1/boilerplate-project-urlshortener: A boilerplate for a freeCodeCamp project.
solution: https://replit.com/@smailove/boilerplate-project-urlshortener

Your browser information:

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

Challenge: URL Shortener Microservice

Link to the challenge:

Before submitting this project I want to add to the get method a way to verify if the link is already exist I tried some code but it seems it is not working

Any tips on how to pass the test

Log the route inputs and outputs. When I do that on a fork of your project, I see:

url:  https://boilerplate-project-urlshortener-4.jeremyagray.repl.co/?v=1629052720221
good url
url:  https://boilerplate-project-urlshortener-4.jeremyagray.repl.co/?v=1629052720398
good url
url:  ftp:/john-doe.org
good url

The last one is not a good URL. So, your test for good or bad URLs is not working.

1 Like

But this url respect the RegExp in javascript for urls

function validateUrl(value) {
  return /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(value);
}

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.