CodeEditorComponent::CodeEditorLine::replaceTabsWithSpaces() endless loop


I'm trying with the JuceDemo project, with the latest version, download today, 03/12/2014.

When running the HTTP sample, it falls on an endless loop if I enter some URLs. If the string returned by the URL contains any special chars, like 'ñ', not encoded, replaceSection() miscalculate the position to insert the spaces (due to CharPointer_UTF8& operator++()), inserting it after the tab position, causing the the endless loop at CodeEditorComponent::CodeEditorLine::replaceTabsWithSpaces().

You can reproduce the behavior with the code below:

    String text = CharPointer_UTF8("the tab is after a special char ñ\tand it will not be replaced with spaces. The space will be inserted after it");
    int tabPos = text.indexOfChar('\t');
    text = text.replaceSection(tabPos, 1, "XXXX");

The result text is "the tab is after a special char ñ\tanXXXX it will not be replaced with spaces. The space will be inserted after it"

I got the same result in Visual Studios 2013 as in XCode 5.1


Hmm.. Well, I don't think there's anything wrong with the replaceTabsWithSpaces method, but perhaps the string has been created from some data that isn't actually UTF-8? If the String class gets given some text that's supposed to be UTF-8 but which contains garbage sequences, then its behaviour will be undefined, and stuff like this could happen.

If anything is to blame in this case it's probably the demo code that loads from the http stream and creates a string, which should probably check that the data is valid before using it.