Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite loop when parsing "/2/" #156

Open
1901 opened this issue May 30, 2018 · 1 comment
Open

Infinite loop when parsing "/2/" #156

1901 opened this issue May 30, 2018 · 1 comment

Comments

@1901
Copy link

1901 commented May 30, 2018

An infinite loop occurs when parsing the string "/2/".

Code snippet:

fsData fd;
fsJsonParser.Parse("/2/", out fd);
@1901
Copy link
Author

1901 commented Jun 4, 2018

I added these three lines to fix this issue.

private void SkipSpace() {
    while (HasValue()) {
        char c = Character();

        // whitespace; fine to skip
        if (char.IsWhiteSpace(c)) {
            TryMoveNext();
            continue;
        }

        // comment?
        if (HasValue(1) && Character(0) == '/') {
            if (Character(1) == '/') {
                // skip the rest of the line
                while (HasValue() && Environment.NewLine.Contains("" + Character()) == false) {
                    TryMoveNext();
                }
                continue;
            }
            else if (Character(1) == '*') {
                // skip to comment close
                TryMoveNext();
                TryMoveNext();
                while (HasValue(1)) {
                    if (Character(0) == '*' && Character(1) == '/') {
                        TryMoveNext();
                        TryMoveNext();
                        TryMoveNext();
                        break;
                    }
                    else {
                        TryMoveNext();
                    }
                }
            }
+            else {
+               TryMoveNext();
+            }
            // let other checks to check fail
            continue;
        }

        break;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant