NSStringMask icon indicating copy to clipboard operation
NSStringMask copied to clipboard

Terminated due to memory issue on version 1.2.2

Open evertoncunha opened this issue 8 years ago • 5 comments

I'm getting "terminated due to memory issue", on version 1.2.2. It's working fine on v1.2.1.

static func maskTitle(readable: String) -> String {
    //let pattern = "(\\d{5}\\.\\d{5} )(\\d{5}\\.\\d{6} )(\\d{5}\\.\\d{6} )(\\d{1} ).*"

    var mask: String = ""

    let count = readable.characters.count
    if count >= 6 {
      mask += "(\\d{5})\\."
    }
    if count >= 11 {
      mask += "(\\d{5}) "
    }
    if count >= 16 {
      mask += "(\\d{5})\\."
    }
    if count >= 22 {
      mask += "(\\d{6}) "
    }
    if count >= 27 {
      mask += "(\\d{5})\\."
    }
    if count >= 33 {
      mask += "(\\d{6}) "
    }
    if count >= 34 {
      mask += "(\\d{1}) "
    }
    mask += "(.*)"

    return NSStringMask.maskString(readable, withPattern: mask) ?? ""
  }

You can try to pass any value, like maskTitle(readable: "1")

evertoncunha avatar Sep 15 '17 16:09 evertoncunha

What are you trying to accomplish with the (.*) at the end? Could you provide an example of a valid formatted string for your patter?

fjcaetano avatar Sep 21 '17 14:09 fjcaetano

It's a pattern for 🇧🇷 barcode payments while you type. Example: 55555 55555.5 55555.55555 55555.55555 5 55555.55555 55555.666666 55555.666666 1 00000000000014

The (.*) at the end is to accept any number after any case of the pattern.

evertoncunha avatar Sep 22 '17 13:09 evertoncunha

You really shouldn't have a group that captures and formats without a limited count. It does fall into an infinite loop in the do-while in [NSStringMask validCharactersForString:(NSString*)]. Could you try limiting the characters captured by that (.*)? Also, by using the dot-star pattern, you'd be capturing any characters, not only digits, spaces and dots.

Perhaps there should be a warning or some other verification at execution time for unlimited repetitions patterns.

fjcaetano avatar Sep 25 '17 17:09 fjcaetano

I do a "numbers only" filter previous this function. But the strange thing is that it works fine at version 1.2.1. I'll stick with the previous version then 🤔 .

evertoncunha avatar Sep 25 '17 18:09 evertoncunha

That is super weird. I couldn't see anything obvious that might have broken it. I'll get back to this when I get the chance, so I'll leave your issue open for now.

fjcaetano avatar Sep 25 '17 18:09 fjcaetano