drewnoakes / figgle

ASCII banner generation for .NET
Apache License 2.0
412 stars 42 forks source link

Fix: in some cases "System.ArgumentOutOfRangeException" exception will happen with a "slant" font. #6

Closed jsakamoto closed 3 years ago

jsakamoto commented 3 years ago

Hi, First thanks for the good work!

I encountered the exception System.ArgumentOutOfRangeException: startIndex cannot be larger than the length of string when I render the text like the "H.W" with "slant" font.

So at first, I added a unit test case that reproduces the System.ArgumentOutOfRangeException exception is occurred. (commit f48454de)

After that, I started to investigate why the exception has occurred. The reason for the exception looked like for me that the toMove value is overrun from the length of FigletCharacter's content string. Therefore, I fixed it by adding the code that adjusts the toMove value must be less or equal the length of FigletCharacter's content string. (commit 14895b4a)

However, another problem happened. The exception never occurred so the first problem was solved, but instead, the behavior of overwrapping in characters was different from the expected one.

I expected that the first character is front before the next character, but the actual behavior is the next character was front before the first character.

Expected:

    __  ___       __
   / / / / |     / /
  / /_/ /| | /| / / 
 / __  /_| |/ |/ /  
/_/ /_/(_)__/|__/   

Actual:

    __  _ _       __
   / / / | |     / /
  / /_/ /| | /| / / 
 / __  /_| |/ |/ /  
/_/ /_/(_)__/|__/

I started to investigate this next problem. After a while, I found the reason of this problem. The reason is, there is no consideration of the end of the character in the FigletCharacter line is exactly space or not, I think.

Finally, I fixed this problem at commit 54153c0b.

I did these works, so I send this pull request for you.

I hope this pull request is helpful for you and all users who use great this package.

Again, thanks for your great works!

drewnoakes commented 3 years ago

Thanks very much for this!

This library would be a great candidate for fuzz testing, come to think of it.

drewnoakes commented 3 years ago

Published in 0.4.0