Skip to content

Commit

Permalink
Extended ASCII is also invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
philipwhitt committed Sep 17, 2015
1 parent 512d9c1 commit 1d0b221
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/Nacha/Field/String.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ public function __construct($value, $length) {
throw new InvalidFieldException('Value "' . $value . '" must be an string.');
}

// ASCII 0-31 are invalid chars
if (strlen($value) > 0) {
foreach (str_split($value) as $char) {
if (ord($char) < 32) {
$ascii = ord($char);

// ASCII 0-31 + extended ASCII are invalid chars.
if ($ascii < 32 || $ascii > 127) {
throw new InvalidFieldException('Invalid ASCII: ' . ord($value));
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/Nacha/Field/StringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public function testNotString() {
}

public function testInvalidCharacter() {
foreach (range(0, 31) as $ascii) {
$asciiValues = array_merge(range(0, 31), range(128, 255));
foreach ($asciiValues as $ascii) {
$invalid = 'validtext'.chr($ascii);

try {
Expand Down

0 comments on commit 1d0b221

Please sign in to comment.