Skip to content

Commit

Permalink
Fix for issue #2 (#3)
Browse files Browse the repository at this point in the history
* Adding failing test for #2 TDD

* Fix for #2
  • Loading branch information
carbontwelve authored Feb 14, 2018
1 parent 1dd7691 commit 7f35356
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Confusable.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ public function isConfusable(string $string, bool $greedy = false, array $prefer
continue;
}

$found = $this->confusablesData[$char];
// The original source uses the Python dictionary get() method which returns a default
// if the key doesn't exist in the dictionary. This solves issue #2.
$found = isset($this->confusablesData[$char]) ? $this->confusablesData[$char] : [];
// Character λ is considered confusable if λ can be confused with a character from
// $preferredAliases, e.g. if 'LATIN', 'ρ' is confusable with 'p' from LATIN.
// if 'LATIN', 'Γ' is not confusable because in all the characters confusable with Γ,
Expand Down
10 changes: 10 additions & 0 deletions tests/ConfusableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ public function testIsConfusable()
// For 'Greek' readers, p is confusable! ↓
$confusable = $confusables->isConfusable('paρa', false, ['greek'])[0]['character'];
$this->assertEquals('p', $confusable);

// Microsoft contains a zero width character - added for #2
$this->assertTrue(is_array($confusables->isConfusable('www.microsоft.com')));
$this->assertTrue(is_array($confusables->isConfusable('www.Αpple.com')));
$this->assertTrue(is_array($confusables->isConfusable('www.faϲebook.com')));

// The three below are all not confusable - added for #2
$this->assertFalse(is_array($confusables->isConfusable('www.microsoft.com', false, ['latin'])));
$this->assertFalse(is_array($confusables->isConfusable('www.apple.com', false, ['latin'])));
$this->assertFalse(is_array($confusables->isConfusable('www.facebook.com', false, ['latin'])));
}

public function testIsDangerous()
Expand Down

0 comments on commit 7f35356

Please sign in to comment.