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

Commit

Permalink
fix(url): fix complicated regex for uris validation (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
char0n authored Mar 6, 2018
1 parent d2edbcd commit 2533be2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
2 changes: 1 addition & 1 deletion releases/latest/amanda.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ Validation.prototype.addAttributeConstructor('format', function formatConstructo
*/
'uri': {
type: 'string',
pattern: /^(?:(?:ht|f)tp(?:s?)\:\/\/|~\/|\/)?(?:\w+:\w+@)?((?:(?:[-\w\d{1-3}]+\.)+(?:com|org|cat|coop|int|pro|tel|xxx|net|gov|mil|biz|info|mobi|name|aero|jobs|edu|co\.uk|ac\.uk|it|fr|tv|museum|asia|local|travel|[a-z]{2})?)|((\b25[0-5]\b|\b[2][0-4][0-9]\b|\b[0-1]?[0-9]?[0-9]\b)(\.(\b25[0-5]\b|\b[2][0-4][0-9]\b|\b[0-1]?[0-9]?[0-9]\b)){3}))(?::[\d]{1,5})?(?:(?:(?:\/(?:[-\w~!$+|.,=]|%[a-f\d]{2})+)+|\/)+|\?|#)?(?:(?:\?(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)(?:&(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)*(?:#(?:[-\w~!$ |\/.,*:;=]|%[a-f\d]{2})*)?$/
pattern: /^[^\s]+$/
},

/**
Expand Down
2 changes: 1 addition & 1 deletion src/engines/json/attributes/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Validation.prototype.addAttributeConstructor('format', function formatConstructo
*/
'uri': {
type: 'string',
pattern: /^(?:(?:ht|f)tp(?:s?)\:\/\/|~\/|\/)?(?:\w+:\w+@)?((?:(?:[-\w\d{1-3}]+\.)+(?:com|org|cat|coop|int|pro|tel|xxx|net|gov|mil|biz|info|mobi|name|aero|jobs|edu|co\.uk|ac\.uk|it|fr|tv|museum|asia|local|travel|[a-z]{2})?)|((\b25[0-5]\b|\b[2][0-4][0-9]\b|\b[0-1]?[0-9]?[0-9]\b)(\.(\b25[0-5]\b|\b[2][0-4][0-9]\b|\b[0-1]?[0-9]?[0-9]\b)){3}))(?::[\d]{1,5})?(?:(?:(?:\/(?:[-\w~!$+|.,=]|%[a-f\d]{2})+)+|\/)+|\?|#)?(?:(?:\?(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)(?:&(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)*(?:#(?:[-\w~!$ |\/.,*:;=]|%[a-f\d]{2})*)?$/
pattern: /^[^\s]+$/
},

/**
Expand Down
21 changes: 8 additions & 13 deletions tests/json/attributes/format/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,12 @@ suite('JSON/Attribute/format#url', function() {

test('should return an error', function() {
[
'google.a',
'google.rog',
'google://google',
'example',
'http://ex.o',
'www.ex.o',
'pam.pam.pam',
'go@gle',
'g::gle',
'☺☻☹.com',
'☜☞☝☟'
'',
' ',
'\n',
'\r',
'\n\r',
'\n\n\n\n\n\n',
].forEach(function(input) {
Validator.validate(input, schema, function(error) {
count += 1;
Expand All @@ -69,8 +64,8 @@ suite('JSON/Attribute/format#url', function() {
});
});

test('should run 18911 times', function() {
expect(count).to.be.eql(18911);
test('should run specified number of times', function() {
expect(count).to.be.eql(18906);
});

});

0 comments on commit 2533be2

Please sign in to comment.