GithubHelp home page GithubHelp logo

Crash for certain strings about gltaplabeldemo HOT 1 OPEN

laullon avatar laullon commented on July 28, 2024
Crash for certain strings

from gltaplabeldemo.

Comments (1)

richardpenner avatar richardpenner commented on July 28, 2024

It looks like you're scanning up to the symbol character set, and then assuming that the symbol part of the scanned string has at least 2 characters:
NSString *word=[read substringWithRange:NSMakeRange(idx, 2)];
I fixed this with the following code:
int charactersToRead = MIN( 2, read.length );
NSString *word=[read substringWithRange:NSMakeRange(idx, charactersToRead)];
But then I found a different bug, where a sentence with a symbol in the middle, like the example above, loses it's space. NSScanners by default have whitespace and newline characters set in charactersToBeSkipped. So in the example string above, after the crash fix, your code scans in "Image ", then "|", then in the second iteration ,the "scanUpToCharactersFromSet" will ignore the " " at the beginning of the remaining string (" Code"). This is all fixed by doing this:
NSScanner *s = [NSScanner scannerWithString:self.text];
[s setCharactersToBeSkipped: nil];
But now, there's a 3rd bug, where it assumes that "words" are separated by spaces. Hence, in a string like this:
@"This is a #test-||-with some symbols."
It is rendered as:
This is a #test- ||-with some symbols.
(Note the extra space between #test- and ||). I don't see an easy way to fix this without re-writing most of this code, so I'll leave it to you. Happy to do a pull request if you care.

from gltaplabeldemo.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.