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

lkml goes into infinite loop #91

Open
EyalDlph opened this issue Mar 1, 2024 · 4 comments
Open

lkml goes into infinite loop #91

EyalDlph opened this issue Mar 1, 2024 · 4 comments

Comments

@EyalDlph
Copy link

EyalDlph commented Mar 1, 2024

when there is a single semi-colon (;) in the file, lkml goes into infinite loop.

In lexer.py, Lexer.scan(), around line 78, is peeking ahead to look for double semi-columns (;;). If it does find it, it just keeps looking forever, not advancing the scan index and not throwing an exception

My quick-fix was to throw an exception if under scan() the lexer encounters a single semi-colon:

        while True:
            ch = self.peek()
            if ch == "\0":
                self.tokens.append(CHARACTER_TO_TOKEN[ch](self.line_number))
                break
            elif ch in "\n\t ":
                self.tokens.append(self.scan_whitespace())
            elif ch == "#":
                self.advance()
                self.tokens.append(self.scan_comment())
            elif ch == ";":
                if self.peek_multiple(2) == ";;":
                    self.advance(2)
                    self.tokens.append(CHARACTER_TO_TOKEN[ch](self.line_number))
                else:
                    raise ValueError(f"Unexpected character in index {self.index}: {ch}")
            elif ch == '"':
                self.advance()
                self.tokens.append(self.scan_quoted_literal())
            elif ch in CHARACTER_TO_TOKEN.keys():
@joshtemple
Copy link
Owner

Hi @EyalDlph, can you please share some sample LookML to help me reproduce this?

@EyalDlph
Copy link
Author

EyalDlph commented Mar 1, 2024

a file with a single semi-colon will do.

@joshtemple
Copy link
Owner

In what context would a single semicolon not in double-quotes and not part of a SQL expression be valid LookML? It's not enough to have a file with a single semicolon.

For example, this parses perfectly well:

view: test_view {
    dimension: test_dim {
        label: "Has a ;"
    }
}

Please provide an example.

@EyalDlph
Copy link
Author

EyalDlph commented Mar 1, 2024

Of course. This is not valid LookML. This is why I was expecting the load() method to return an exception. Instead, it goes into an infinite loop. In fact, I ran into this example when trying to parse a whole directory and one of the files was broken. I didn't know that. I can't share the actual file, but you can reproduce this with this file:

view name {
  ;
}

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

2 participants