Skip to content

Substring issue #14

@AnEvilPenguin

Description

@AnEvilPenguin

Hi,
I've come across an issue where in certain cases the Split-Word function seems to over-loop (the 2nd url sets off the error for me and does so even when just sending that into the function):

(Invoke-RestMethod -Method Get -Uri "https://istheinternetonfire.com/status.json").issues.urls | cowsay
Exception calling "Substring" with "1" argument(s): "startIndex cannot be larger than length of string.
Parameter name: startIndex"
At line:230 char:7
+       $splits += $word.substring($startPoint)
+       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentOutOfRangeException

 __________________________________________
/ https://www.drownattack.com/             \
| https://openssl.org/news/secadv/20160301 |
| .txt                                     |
| http://blog.cryptographyengineering.com/ |
\ 2016/03/attack-of-week-drown.html        /
 ------------------------------------------
      \  ^__^             
       \ (oo)\________    
         (__)\        )\/\
              ||----w |   
              ||     ||

I've managed to get around this by adding a break in as follows. I can't see specifically why this is over shooting on the for loop though as I've never tried to use a for loop in that way myself.

function Split-Word($word) {
  if($word.length -le $bubbleWidth) {
    return ,[string[]]@($word)
  }

  $splits = [string[]]@()

  foreach($i in (0..($word.length / $bubbleWidth))) {
    $startPoint = ($i * $bubbleWidth)
    if(($startPoint + $bubbleWidth) -gt $word.length) {
      $splits += $word.substring($startPoint)
      break
    } else {
      $splits += $word.substring($startPoint, $bubbleWidth)
    }
  }

  return ,[string[]]$splits
}

Sorry just joined git to post this issue.

Just in case it helps:

$PSVersionTable

Name                           Value                                                                                                                                                                     
----                           -----                                                                                                                                                                     
PSVersion                      5.0.10586.117                                                                                                                                                             
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                   
BuildVersion                   10.0.10586.117                                                                                                                                                            
CLRVersion                     4.0.30319.42000                                                                                                                                                           
WSManStackVersion              3.0                                                                                                                                                                       
PSRemotingProtocolVersion      2.3                                                                                                                                                                       
SerializationVersion           1.1.0.1  

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions