HI.
I’m doing the URL Shortener Microservice challenge.
The verification system tells me that I fail the fourth test, the one that says:
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' }
The application I wrote locally checks the validity of the URL; in particular the check is carried out with the following function:
const isValidUrl = (url) => {
try {
new URL(url);
return true;
} catch (err) {
return false;
}
};
Investigating the problem on the developer tools of my browser I seem to understand that the URL that should be rejected is https://r.stripe.com/b
, which instead my application accepts and records in the database. The following node
session demonstrates that the url is formally valid:
user$ node
Welcome to Node.js v18.16.0.
Type ".help" for more information.
> let a = new URL('https://r.stripe.com/b')
undefined
> a
URL {
href: 'https://r.stripe.com/b',
origin: 'https://r.stripe.com',
protocol: 'https:',
username: '',
password: '',
host: 'r.stripe.com',
hostname: 'r.stripe.com',
port: '',
pathname: '/b',
search: '',
searchParams: URLSearchParams {},
hash: ''
}
- Could you tell me if my analysis is correct?
- What are the criteria that the application must use to consider a URL as valid or invalid?
Thank you.