Skip to content

Enforce recursion depth limits for ternary expressions in the Pratt parser. - #1497

Open
dmitriplotnikov wants to merge 2 commits into
masterfrom
pratt-parser-ternary-recursion-limit
Open

dmitriplotnikov wants to merge 2 commits into
masterfrom
pratt-parser-ternary-recursion-limit

Conversation

@dmitriplotnikov

Copy link
Copy Markdown
Collaborator

Enforce MaxRecursionDepth when parsing ternary conditional expressions (? :) in the Pratt parser by tracking recursion depth in parseTernary and terminating parseBinaryAndTernary once the recursion or recovery limit is exceeded.

Comment thread parser/pratt_parser.go Outdated
return lhs
}
p.recursionDepth++
defer func() { p.recursionDepth-- }()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This turned out quite a bit more expensive than just explicitly decrementing recursionDepth. I am making this adjustment in the second commit in this PR

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

Successfully merging this pull request may close these issues.

3 participants