瀏覽代碼

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

Pouria Ezzati 8 年之前
父節點
當前提交
125e9bab4a
共有 1 個文件被更改,包括 2 次插入1 次删除
  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.' });
   }