fix(regex.util): check that 'http(s)' protocol is included in URL
Pour tester tu peux copier/coller ça dans la console de ton navigateur:
function isValidURL(url) {
const urlRegex = new RegExp("^https?://[^\\s/$.?#].[^\\s]*$", "i");
return urlRegex.test(url);
}
function testUrl(url) {
console.log(url + " : " + isValidURL(url));
}
testUrl("http://www.alaxos.com");
testUrl("http://www.aLaXos.coM");
testUrl("https://www.alaxos.com");
testUrl("https://www.aLaXos.coM");
testUrl("http://www.alaxos.com/test");
testUrl("http://wWw.aLaXos.coM/tEst");
testUrl("https://www.alaxos.com/test");
testUrl("https://wWw.aLaXos.coM/tEst");
testUrl("http://www.alaxos.com/test/test");
testUrl("http://wWw.aLaXos.coM/tEst/tEst");
testUrl("https://www.alaxos.com/test/test");
testUrl("https://wWw.aLaXos.coM/tEst/tEst");
testUrl("http://www.alaxos.com/test/test.txt");
testUrl("http://wWw.aLaXos.coM/test/tEst.txt");
testUrl("https://www.alaxos.com/test/test.txt");
testUrl("https://wWw.aLaXos.coM/test/tEst.txt");
testUrl("http://www.test.alaxos.com/test/test");
testUrl("https://www.test.alaxos.com/test/test");
testUrl("http://www.test.alaxos.com/test-1/test-2");
testUrl("https://www.test.alaxos.com/test-1/test-2");
testUrl("http://www.test.alaxos.com/test-1/test-2.txt");
testUrl("https://www.test.alaxos.com/test-1/test-2.txt");
testUrl("http://www.test.alaxos.com/test-1/test-2/key:value");
testUrl("https://www.test.alaxos.com/test-1/test-2/key:value");
testUrl("http://www.test.alaxos.com/test-1/test-2/key:value/test");
testUrl("https://www.test.alaxos.com/test-1/test-2/key:value/test");
testUrl("http://www.test.alaxos.com/test-1/test-2/key:value/test.html");
testUrl("https://www.test.alaxos.com/test-1/test-2/key:value/test.html");
testUrl("http://www.alaxos.");
testUrl("https://www.alaxos.");
testUrl("http://www.alaxos.com/*ç%&/(");
testUrl("https://www.alaxos.com/*ç%&/(");
testUrl("http://www.alaxos.com/*ç%&/test/test");
testUrl("https://www.alaxos.com/*ç%&/test/test");
testUrl("http://www.alaxos.com/test!/test");
testUrl("https://www.alaxos.com/test!/test");
testUrl("http://www.alaxos.com/test!/test");
testUrl("https://www.alaxos.com/test!/test");
testUrl("http://www.alaxos.com/test$/test");
testUrl("https://www.alaxos.com/test$/test");
testUrl("http://www.alaxos.com/test/test#test");
testUrl("https://www.alaxos.com/test/test#test");
testUrl("http://www.alaxos.com/test#/test");
testUrl("https://www.alaxos.com/test#/test");
testUrl("http://www.alaxos.com/test/test?test=test");
testUrl("https://www.alaxos.com/test/test?test=test");
testUrl("http://www.alaxos.com/test/test?test=test&test=test");
testUrl("https://www.alaxos.com/test/test?test=test&test=test");
testUrl("http://www.alaxos.com/test/test?test=test&test!=test!");
testUrl("https://www.alaxos.com/test/test?test=test&test!=test!");
testUrl("http://alaxos.com/test!/test");
testUrl("https://alaxos.com/test!/test");
testUrl("http://alaxos.com/test$/test");
testUrl("https://alaxos.com/test$/test");
testUrl("http://alaxos.com/test/test#test");
testUrl("https://alaxos.com/test/test#test");
testUrl("http://alaxos.com/test#/test");
testUrl("https://alaxos.com/test#/test");
testUrl("http://alaxos.com/test/test?test=test");
testUrl("https://alaxos.com/test/test?test=test");
testUrl("http://alaxos.com/test/test?test=test&test=test");
testUrl("https://alaxos.com/test/test?test=test&test=test");
testUrl("http://alaxos.com/test/test?test=test&test!=test!");
testUrl("https://alaxos.com/test/test?test=test&test!=test!");
testUrl("https://localhost")
testUrl("http://localhost")
testUrl("https://localhost/test")
testUrl("http://localhost/test")
testUrl("htpp://www.alaxos.com");
testUrl("htpps://www.alaxos.com");
testUrl("http//www.alaxos.com");
testUrl("https//www.alaxos.com");
testUrl("http:///www.alaxos.com");
testUrl("https:///www.alaxos.com");
testUrl("www.alaxos.com");
testUrl("htttp://www.alaxos.com");
testUrl("test");
testUrl("test/test");
testUrl("test-1/test-2");
testUrl("test.com/test-2");
testUrl("test/test-2.com");