Commits

Toby Inkster  committed 20c0dad

s/strlen/length/

  • Participants
  • Parent commits bb0125a

Comments (0)

Files changed (2)

File lib/JSON/Schema/Helper.pm

 					unless $value ~~ $format_checker;
 			}
 			if ($schema->{'maxLength'} and $self->jsMatchType('string', $value)
-			and strlen($value) > $schema->{'maxLength'})
+			and length($value) > $schema->{'maxLength'})
 			{
 				$addError->("may only be " . $schema->{'maxLength'} . " characters long");
 			}
 			if ($schema->{'minLength'} and $self->jsMatchType('string', $value)
-			and strlen($value) < $schema->{'minLength'})
+			and length($value) < $schema->{'minLength'})
 			{
 				$addError->("must be at least " . $schema->{'minLength'} . " characters long");
 			}

File t/06lengths.t

+use strict;
+use warnings;
+use Test::More;
+
+use JSON::Schema;
+
+my $S = "JSON::Schema"->new(
+	{
+		type => 'object',
+		properties => {
+			username => { minLength => 1, maxLength => 64, required => 1 },
+			password => { minLength => 6,                  required => 1 },
+		},
+	},
+);
+
+ok     $S->validate({ username => 'abc', password => 'abcdef' });
+ok     $S->validate({ username => 'abc', password => 'abcdefgh' });
+ok not $S->validate({ username => 'abc', password => 'abcde' });
+ok not $S->validate({ username => 'abc' });
+ok not $S->validate({ password => 'abcdefgh' });
+ok not $S->validate({ username => '', password => 'abcdefgh' });
+ok not $S->validate({ username => ('a' x 65), password => 'abcdefgh' });
+
+done_testing;