Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #10844 from arcturus/bug-890342
Browse files Browse the repository at this point in the history
Bug 890342 - [SMS] LinkHelper regression: misrecognized links
  • Loading branch information
arcturus committed Jul 9, 2013
2 parents 45cbc46 + 1aceea0 commit 3ec4322
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
19 changes: 13 additions & 6 deletions apps/sms/js/link_helper.js
Expand Up @@ -6,14 +6,21 @@
anchor links for url, phone, email.
*/

var ipv4RegExp = new RegExp(
'^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$');
// ensure that each part of the domain is long enough
function checkDomain(domain) {
var parts = domain.split('.');
// either the tld is more than one character or it is an IPv4
return parts[parts.length - 1].length > 1 ||
parts.length === 4 && parts.every(function(part) {
return part >= 0 && part < 256;
});
// Check for a specific IPv4 address
if (ipv4RegExp.test(domain)) {
return true;
} else {
// Don't add many restrictions,
// just the tld to be non numeric and length > 1
var parts = domain.split('.');
var lastPart = parts[parts.length - 1];
// We want the last part not to be a number
return lastPart.length > 1 && !isFinite(lastPart);
}
}

// defines things that can match right before to be a "safe" link
Expand Down
6 changes: 6 additions & 0 deletions apps/sms/test/unit/link_helper_test.js
Expand Up @@ -166,6 +166,12 @@ suite('link_helper_test.js', function() {
test('Simple URL with IPv6', function() {
testURLNOK('http://[::1]/');
});
test('Bug 890342 1', function() {
testURLNOK('2.74');
});
test('Bug 890342 2', function() {
testURLNOK('21.72');
});
});
});

Expand Down

0 comments on commit 3ec4322

Please sign in to comment.