Sfoglia il codice sorgente

add protocol if the link doesn't have one. Fixes #6

Pouria Ezzati 8 anni fa
parent
commit
125e9bab4a
1 ha cambiato i file con 2 aggiunte e 1 eliminazioni
  1. 2 1
      server/controllers/urlController.js

+ 2 - 1
server/controllers/urlController.js

@@ -42,7 +42,8 @@ exports.urlShortener = async ({ body, user }, res) => {
   }
   const isValidUrl = urlRegex({ exact: true, strict: false }).test(body.target);
   if (!isValidUrl) return res.status(400).json({ error: 'URL is not valid.' });
-  const target = URL.parse(body.target).protocol ? body.target : `http://${body.target}`;
+  const hasProtocol = /^https?/.test(URL.parse(body.target).protocol);
+  const target = hasProtocol ? body.target : `http://${body.target}`;
   if (body.password && body.password.length > 64) {
     return res.status(400).json({ error: 'Maximum password length is 64.' });
   }